java GUI 模仿计算器界面的代码有点小问题。(如图,如何让下拉菜单下面的两行压扁一点?)
代码:importjava.awt.*;publicclassCalculator{publicstaticvoidmain(String[]args){Framef=n...
代码:
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();
}
} 展开
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();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询