Java小程序有错误,高手帮忙指点下,在线等,谢谢!
importjava.awt.*;importjava.awt.event.*;classAextendsFrameimplementsActionListener{Te...
import java.awt.*;
import java.awt.event.*;
class A extends Frame implements ActionListener
{TextField text1,text2,text3;
Button jia,cha,ji,chu;
A(String s)
{super(s);
setLayout(new FlowLayout());
text1=new TextField();
text2=new TextField();
text3=new TextField();
text3.setEditable(false);
jia=new Button("加");
cha=new Button("减");
ji=new Button("乘");
chu=new Button("除");
jia.addActionListener(this);
cha.addActionListener(this);
ji.addActionListener(this);
chu.addActionListener(this);
add(text1);
add(text2);
add(text3);
add(jia);
add(cha);
add(ji);
add(chu);
setBounds(100,100,200,200);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{try{int i,j,n;
i=Integer.parseInt(text1.getText());
j=Integer.parseInt(text2.getText());
if(e.getSource()==jia)
{n=i+j;}
else if(e.getSource()==cha)
{n=i-j;}
else if(e.getSource()==ji)
{n=i*j;}
else if(e.getSource()==chu)
{n=i/j;}
String s=String valueOf(n);
text3.setText(s);
}
catch(NumberFormatException e)
{text3.setText("");
}
}
}
public class CC
{public static void main (String[] args) {
A a=new A("请输入数字!");
}
} 展开
import java.awt.event.*;
class A extends Frame implements ActionListener
{TextField text1,text2,text3;
Button jia,cha,ji,chu;
A(String s)
{super(s);
setLayout(new FlowLayout());
text1=new TextField();
text2=new TextField();
text3=new TextField();
text3.setEditable(false);
jia=new Button("加");
cha=new Button("减");
ji=new Button("乘");
chu=new Button("除");
jia.addActionListener(this);
cha.addActionListener(this);
ji.addActionListener(this);
chu.addActionListener(this);
add(text1);
add(text2);
add(text3);
add(jia);
add(cha);
add(ji);
add(chu);
setBounds(100,100,200,200);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{try{int i,j,n;
i=Integer.parseInt(text1.getText());
j=Integer.parseInt(text2.getText());
if(e.getSource()==jia)
{n=i+j;}
else if(e.getSource()==cha)
{n=i-j;}
else if(e.getSource()==ji)
{n=i*j;}
else if(e.getSource()==chu)
{n=i/j;}
String s=String valueOf(n);
text3.setText(s);
}
catch(NumberFormatException e)
{text3.setText("");
}
}
}
public class CC
{public static void main (String[] args) {
A a=new A("请输入数字!");
}
} 展开
1个回答
展开全部
有问题 可以hi我
import java.awt.*;
import java.awt.event.*;
class A extends Frame implements ActionListener {
TextField text1, text2, text3;
Button jia, cha, ji, chu;
A(String s) {
super(s);
setLayout(new FlowLayout());
text1 = new TextField();
text2 = new TextField();
text3 = new TextField();
text3.setEditable(false);
jia = new Button("加");
cha = new Button("减");
ji = new Button("乘");
chu = new Button("除");
jia.addActionListener(this);
cha.addActionListener(this);
ji.addActionListener(this);
chu.addActionListener(this);
add(text1);
add(text2);
add(text3);
add(jia);
add(cha);
add(ji);
add(chu);
setBounds(100, 100, 200, 200);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{try{int i,j,n = 0;
i=Integer.parseInt(text1.getText());
j=Integer.parseInt(text2.getText());
if(e.getSource()==jia)
{n=i+j;}
else if(e.getSource()==cha)
{n=i-j;}
else if(e.getSource()==ji)
{n=i*j;}
else if(e.getSource()==chu)
{n=i/j;}
String s=String.valueOf(n);
text3.setText(s);
}
catch(NumberFormatException f)
{text3.setText("");
}
}
}
public class CC {
public static void main(String[] args) {
A a = new A("请输入数字!");
}
}
import java.awt.*;
import java.awt.event.*;
class A extends Frame implements ActionListener {
TextField text1, text2, text3;
Button jia, cha, ji, chu;
A(String s) {
super(s);
setLayout(new FlowLayout());
text1 = new TextField();
text2 = new TextField();
text3 = new TextField();
text3.setEditable(false);
jia = new Button("加");
cha = new Button("减");
ji = new Button("乘");
chu = new Button("除");
jia.addActionListener(this);
cha.addActionListener(this);
ji.addActionListener(this);
chu.addActionListener(this);
add(text1);
add(text2);
add(text3);
add(jia);
add(cha);
add(ji);
add(chu);
setBounds(100, 100, 200, 200);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{try{int i,j,n = 0;
i=Integer.parseInt(text1.getText());
j=Integer.parseInt(text2.getText());
if(e.getSource()==jia)
{n=i+j;}
else if(e.getSource()==cha)
{n=i-j;}
else if(e.getSource()==ji)
{n=i*j;}
else if(e.getSource()==chu)
{n=i/j;}
String s=String.valueOf(n);
text3.setText(s);
}
catch(NumberFormatException f)
{text3.setText("");
}
}
}
public class CC {
public static void main(String[] args) {
A a = new A("请输入数字!");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询