计算器
package win;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import static javax.swing.JFrame.*;
class win extends JFrame implements ActionListener{
JTextField text1=new JTextField(10);
JTextField text2=new JTextField(10);
JTextField text3=new JTextField(10);
JTextField text4=new JTextField(10);
win(String s){
super(s);
setSize(400,600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
text3.addActionListener(this);
text4.setEditable(false);
add(text1);
add(text2);
add(text3);
add(text4);
setLayout(new FlowLayout());
}
public void actionPerformed(ActionEvent e){
String s1=text1.getText();
String s2=text1.getText();
String s3=text1.getText();
try {
int a=Integer.parseInt(s1);
int b=Integer.parseInt(s2);
int c=Integer.parseInt(s3);
int m=a+b+c;
text4.setText(""+m);
}
catch(Exception ee){
System.out.println("ERROR");
}
}
}
public class window {
public static void main(String args[]){
new win("huxinwen");
}
}
浙公网安备 33010602011771号