日期:2014-05-20 浏览次数:20758 次
import java.awt.*; import java.awt.event.*; public class TFmath{ public static void main(String[] args){ new MyFrame(); } } class MyFrame extends Frame{ public MyFrame(){ setLayout(new FlowLayout()); TextField num1 = new TextField(10); TextField num2 = new TextField(10); TextField num3 = new TextField(15); Label lab = new Label("+"); Button bun = new Button("="); bun.addActionListener(new minitor(this)); add(num1); add(lab); add(num2); add(bun); add(num3); pack(); setVisible(true); } } class Minitor implements ActionListener{ MyFrame mf = null; Minitor(MyFrame mf){ this.mf = mf; } public void actionPerformed(ActionEvent e){ int n1 = Integer.parseInt(mf.num1.getText()); int n2 = Integer.parseInt(mf.num2.getText()); int n3 = (n1 + n2); mf.num3.setText(String.valueOf(n3)); } }