java简单的计算器布局无功能实现-使用BorderLayout和GridLayout布局

import java.awt.*;
import javax.swing.*;
public class Main extends JFrame{
        public static void main(String[] args) {
            // 创建JFrame
            Main  frame = new Main();
            //
            frame.setTitle("A Simple Calculate Application ");
            // 设置尺寸
            frame.setSize(500, 500);
            // JFrame在屏幕居中
            frame.setLocationRelativeTo(null);
            // JFrame关闭时的操作
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            // 显示JFrame
            frame.setVisible(true);
            //设置窗体不可拖动
//            frame.setResizable(false);
        }
    public Main() {
        //设置总的布局格式为边界布局管理器
        setLayout(new BorderLayout());
        JTextField a1 = new JTextField();
        a1.setFont(new Font("宋体", Font.PLAIN, 50) );//设置Text框大小样式
        getContentPane().add("North",a1);//使在最上边显示
        //设置一个容器。四行四列
        JPanel p1 = new JPanel(new GridLayout(4,4));
        getContentPane().add("Center",p1);//将容器添加到Jframe里面
        String str[]= {"7","8","9","-","4","5","6","+","1","2","3","/","0","."," ","="};
        for(int i =0;i

你可能感兴趣的:(计算器布局)