源代码:
package ji;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import javax.swing.JFrame;
public class Add extends JFrame{
//private static final int ON = 0;
//private static final int CLOSE = 0;
public Add() {
super("运算器");
this.setSize(400,200);
this.setLocation(300,240);
this.setBackground(Color.white);
this.setLayout(new FlowLayout());
this.add(new TextField("10",8));
this.add(new Label("+"));
this.add(new TextField("20",8));
this.add(new Button("="));
this.add(new TextField(10));
this.add(new TextField("30",8));
this.add(new Label("-"));
this.add(new TextField("20",8));
this.add(new Button("="));
this.add(new TextField(10));
this.add(new TextField("10",8));
this.add(new Label("*"));
this.add(new TextField("20",8));
this.add(new Button("="));
this.add(new TextField(10));
this.add(new TextField("10",8));
this.add(new Label("/"));
this.add(new TextField("2",8));
this.add(new Button("="));
this.add(new TextField(10));
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[]arg)
{
new Add();
}
}
运行结果:
心得:
对本次实验花了很多时间,但还是理解不够深刻,只能做出基本的窗口和按钮等等,对如何运算现在还不懂,希望能在接下来的学习中学习到。