import java.awt.*;
import java.awt.event.*;
import javax.management.monitor.Monitor;
import javax.swing.*;
import javax.swing.event.*;
@SuppressWarnings({ "serial", "unused" })
class Counter extends JFrame{
public Counter() {
baseinfo();
}
public Counter(String title) {
super(title);
baseinfo();
}
private void baseinfo() {
int i = 1;
JTextField ta1 = new JTextField();
Container cp = this.getContentPane();
cp.setLayout(new BorderLayout());
cp.add(ta1, BorderLayout.NORTH);
JPanel p = new JPanel();
p.setLayout(new GridLayout(4, 4, 0, 0));
JButton Button = new JButton();
for (i = 1; i <= 16; i++) {
if (i == 10)
p.add(new Button("0"));
else if (i == 11)
p.add(new Button("."));
else if (i == 12)
p.add(new Button("-"));
else if (i == 13)
p.add(new Button("+"));
else if (i == 14)
p.add(new Button("*"));
else if (i == 15)
p.add(new Button("/"));
else if (i == 16)
p.add(new Button("="));
else {
p.add(new Button("" + i));
}
}
cp.add(p, BorderLayout.CENTER);
}
}
public class GUI {
public static void main(String[] args) {
JFrame frame = new Counter("计算器");
frame.setSize(300, 300);
frame.setResizable(false);// 设置窗口不可放大。
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);// 窗口居中
}
}