预期结果
实现代码:
1 package 图形用户界面设计;
2 import java.awt.*;
3 import javax.swing.*;
4 public class App_net {
5 public App_net()
6 {
7 // 创建JFrame
8 nett frame = new nett();
9 //标题
10 frame.setTitle("Calculate");
11 // 设置尺寸
12 frame.setSize(500, 500);
13 // JFrame在屏幕居中
14 frame.setLocationRelativeTo(null);
15 // JFrame关闭时的操作
16 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
17 // 显示JFrame
18 frame.setVisible(true);
19 //设置窗体不可拖动
20 frame.setResizable(false);
21 }
22 }
23 class nett extends JFrame{
24 public nett() {
25 //设置总的布局格式为边界布局管理器
26 setLayout(new BorderLayout());
27 //setLayout(new GridLayout(4,4));
28 JTextField a1 = new JTextField();
29 a1.setFont(new Font("宋体", Font.PLAIN, 50) );
30 //设置Text框大小样式
31 getContentPane().add("North",a1);
32 //使在最上边显示
33 //设置一个容器,四行四列
34 JPanel p1 = new JPanel(new GridLayout(4,4));
35 getContentPane().add("Center",p1);
36 //将容器添加到Jframe里面
37 String str[]= {"7","8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"};
38 for(int i =0;i<str.length;i++)
39 {
40 JButton str1=new JButton(str[i]);
41 p1.add(str1);
42 str1.setFont(new Font("宋体",Font.BOLD,20));
43 }
44 }
45 }
心得:
布局函数不熟练
以上,结束
@勤劳的l3