62,614
社区成员
发帖
与我相关
我的任务
分享
import java.awt.*;
import java.awt.event.*;
public class TestMath {
public static void main(String args[]) {
new FFrame().Text();
}
}
class FFrame extends Frame {
TextField num1, num2, num3;
public void Text() {
num1 = new TextField(20);
num2 = new TextField(20);
num3 = new TextField(21);
Label pluschar = new Label("+");
Button btnequal = new Button("=");
setLayout(new FlowLayout());
add(num1);
add(pluschar);
add(num2);
btnequal.addActionListener(new monitor(this));
add(btnequal);
add(num3);
pack();
setVisible(true);
}
}
class monitor implements ActionListener {
FFrame tf = null;
public monitor(FFrame tf) {
this.tf = tf;
}
public void actionPerformed(ActionEvent e) {
int n1 = Integer.parseInt(tf.num1.getText());
int n2 = Integer.parseInt(tf.num2.getText());
tf.num3.setText("" + (n1 + n2));
// tf.num1.setText(""); tf.num2.setText("");
}
}
class monitor implements ActionListener {
FFrame tf = null;
public monitor(FFrame tf) {
this.tf = tf;
}
class monitor implements ActionListener {
FFrame tf = new FFrame();
public monitor(FFrame tf) {
this.tf = tf;
}