代码:importjava.awt.*;publicclassCalculator{publicstaticvoidmain(String[]args){Framef=newFrame("计算器");f.setLocation(200,200);f.setVisible(true);MenuBarmb=newMenuBar()...
代码:
import java.awt.*;
public class Calculator{
public static void main(String[]args) {
Frame f = new Frame("计算器");
f.setLocation(200,200);
f.setVisible(true);
MenuBar mb = new MenuBar();
f.setMenuBar(mb);
Menu m3 = new Menu("帮助(H)");
Menu m2 = new Menu("编辑(E)");
mb.add(m2);
mb.add(m3);
m3.add(new MenuItem("查看帮助"));
m3.addSeparator();
m3.add(new MenuItem("关于计算器"));
m2.add(new MenuItem("复制"));
m2.add(new MenuItem("粘贴"));
m2.addSeparator();
m2.add(new MenuItem("历史记录"));
f.setLayout(new GridLayout(3,1,5,5));
TextField screen = new TextField();
Panel p1 = new Panel();
p1.setLayout(new GridLayout(1,4));
p1.add(new TextField());
p1.add(new Button("Backspace"));
p1.add(new Button("CE"));
p1.add(new Button("C"));
Panel p2 = new Panel();
p2.setLayout(new GridLayout(4,6));
Button b[] = {/*此处有24个button创建,由于字数限制,把它删了*/};
for(int i=0; i<24; i++) {
p2.add(b[i]);
}
f.add(screen);
f.add(p1);
f.add(p2);
f.pack();
}
}
展开