import java.awt.*;
import java.awt.event.*;
public class TFMath {
public static void main(String args[]){
new TFFrame().launchFrame();
}}
class TFFrame extends Frame{
TextField num1=new TextField(10);
TextField num2=new TextField(10);
TextField num3=new TextField(15);
public void launchFrame(){
Label lbPlus=new Label("+");
Button btnEqual=new Button("=");
setLayout(new FlowLayout());
add(num1);
add(lbPlus);
add(num2);
add(btnEqual);
add(num3);
pack();
setVisible(true);
setLocation(300,400);//设置窗口在屏幕上显示的位置
btnEqual.addActionListener(new MyMonitor());//为等号添加监听
//匿名内部类,实现窗口关闭
/*this.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});*/
}
class MyMonitor implements ActionListener{
public void actionPerformed(ActionEvent e){
int n1=Integer.parseInt(num1.getText());
int n2=Integer.parseInt(num2.getText());
//int n3=Integer.parseInt(num3.getText());
num3.setText(String.valueOf(n1+n2));
}
}
} 这个程序到底是什么问题啊?? |