麻烦你在百忙之中看一下计算器,我很急用,显示public void actionPerformed(ActionEvent e){ 有12个错误
importjava.awt.*;importjava.awt.event.*;publicclassCalculatorextendsFrameimplementsAc...
import java.awt.*;
import java.awt.event.*;
public class Calculator extends Frame implements ActionListener{
private Frame f;
private double result;
private boolean operated=false;
private Button btn[]=new Button[17];
private TextField tf;
public Calculator(){
f=new Frame("Calculator");
f.setLayout(new BorderLayout());
f.setSize(190,200);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
Panel centerPanel=new centerPanel();
centerPanel.setLayout(new GirdLayout(5,3));
btn[10]=new Button("+");
btn[11]=new Button("-");
btn[12]=new Button("*");
btn[13]=new Button("/");
btn[14]=new Button("√");
btn[15]=new Button("∧");
btn[16]=new Button("=");
for(int i=0;i<10;i++){
btn[i]=new Button(String.valueOf(i));
}
for(int i=0;i<=14;i++){centerPanel.add(btn[i]); }
for(int i=0;i<=14;i++){if(i%2==1){centerPanel.add(btn[(i+19)/2]);}
f.add(centerPanel,BorderLayout.CENTER);
Panel southPanel=new southPanel();
FlowLayout flow=new FlowLayout();
southPanel.setLayout(flow);
southPanel.add(btn[15]);
southPanel.add(btn[16]);
f.add(BorderLayout.SOUTH,southPanel);
Panel northPanel=new northPanel();
tf=new TextField(20);
tf.setEditable(false);
northPanel.add(tf);
f.add(northPanel,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e){
double currentNunber=Double.valueOf(tf.getText()).doubleValue();
if(e.getSource()==btn[10]){result+=currentNumber;operated=false;}
else if(e.getSource()==btn[11]){result-=currentNumber;operated=false;}
else if(e.getSource()==btn[12]){result*=currentNumber;operated=false;}
else if(e.getSource()==btn[13]){if(currentNumber==0) result=0;else result/=currentNumber;operated=false;}
else if(e.getSource()==btn[14]){result=Math.sqrt(currentNumber);operated=true;result=currentNumber;}
else if(e.getSource()==btn[15]){result=Math.pow(currentNumber,2);operated=true;result=currentNumber;}
else if(e.getSource()==btn[16]){operated=true;if(operated){result=currentNumber;}}
else{
if(operated)
result=0;
for(int i=0;i<10;i++)
if(e.getSource()==btn[i]){
if(tf.getText().equals("0"))
tf.setText(""+i);
else if(!operated)
tf.setText(tf.getText()+"i");
else{tf.setText(""+i);operated=false;}
}
}
}
public static void main(String args[]){
new Calculator();}
} 展开
import java.awt.event.*;
public class Calculator extends Frame implements ActionListener{
private Frame f;
private double result;
private boolean operated=false;
private Button btn[]=new Button[17];
private TextField tf;
public Calculator(){
f=new Frame("Calculator");
f.setLayout(new BorderLayout());
f.setSize(190,200);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
Panel centerPanel=new centerPanel();
centerPanel.setLayout(new GirdLayout(5,3));
btn[10]=new Button("+");
btn[11]=new Button("-");
btn[12]=new Button("*");
btn[13]=new Button("/");
btn[14]=new Button("√");
btn[15]=new Button("∧");
btn[16]=new Button("=");
for(int i=0;i<10;i++){
btn[i]=new Button(String.valueOf(i));
}
for(int i=0;i<=14;i++){centerPanel.add(btn[i]); }
for(int i=0;i<=14;i++){if(i%2==1){centerPanel.add(btn[(i+19)/2]);}
f.add(centerPanel,BorderLayout.CENTER);
Panel southPanel=new southPanel();
FlowLayout flow=new FlowLayout();
southPanel.setLayout(flow);
southPanel.add(btn[15]);
southPanel.add(btn[16]);
f.add(BorderLayout.SOUTH,southPanel);
Panel northPanel=new northPanel();
tf=new TextField(20);
tf.setEditable(false);
northPanel.add(tf);
f.add(northPanel,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e){
double currentNunber=Double.valueOf(tf.getText()).doubleValue();
if(e.getSource()==btn[10]){result+=currentNumber;operated=false;}
else if(e.getSource()==btn[11]){result-=currentNumber;operated=false;}
else if(e.getSource()==btn[12]){result*=currentNumber;operated=false;}
else if(e.getSource()==btn[13]){if(currentNumber==0) result=0;else result/=currentNumber;operated=false;}
else if(e.getSource()==btn[14]){result=Math.sqrt(currentNumber);operated=true;result=currentNumber;}
else if(e.getSource()==btn[15]){result=Math.pow(currentNumber,2);operated=true;result=currentNumber;}
else if(e.getSource()==btn[16]){operated=true;if(operated){result=currentNumber;}}
else{
if(operated)
result=0;
for(int i=0;i<10;i++)
if(e.getSource()==btn[i]){
if(tf.getText().equals("0"))
tf.setText(""+i);
else if(!operated)
tf.setText(tf.getText()+"i");
else{tf.setText(""+i);operated=false;}
}
}
}
public static void main(String args[]){
new Calculator();}
} 展开
展开全部
"centerPanel.setLayout(new GirdLayout(5,3));"
----->GridLayout
Panel centerPanel=new centerPanel();
----->没有centerPanel这个类- - ..
Panel southPanel=new Panel();
double currentNunber=Double.valueOf(tf.getText()).doubleValue();
----->double currentNumber
----->GridLayout
Panel centerPanel=new centerPanel();
----->没有centerPanel这个类- - ..
Panel southPanel=new Panel();
double currentNunber=Double.valueOf(tf.getText()).doubleValue();
----->double currentNumber
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询