Swing 是一个为Java设计的GUI工具包。
java swing 包中的常用类:JButton ,JFrame,JPanel ,JTextField,JLabel ,JMenuBar ,JMenuItem ,JMenu 等
今天简单写一下窗口和面板的使用
JPanel
JPanel 面板 是一种中间层容器,它能容纳组件并将组件组合在一起,但它本身必须添加到其他容器中使用。
JFrame
JFrame 是 Swing 组件的顶层容器,该类继承了 AWT 的 Frame 类,支持 Swing 体系结构的高级 GUI 属性。当创建一个 JFrame 类的实例化对象后,其他组件并不能够直接放到容器上面,需要将组件添加至内容窗格,而不是直接添加至 JFrame 对象。
//JFrame窗体
JFrame fmlg = new JFrame();
fmlg.setTitle("管理系统登录");
fmlg.setBounds((sw-fmwidth)/2, (sh-fmheight)/2, fmwidth, fmheight);
fmlg.setDefaultCloseOperation(fmlg.EXIT_ON_CLOSE);
//面板容器
JPanel pContent = new JPanel();
pContent.setLayout(null);
pContent.setBounds(0, 0, fmwidth, fmheight);
pContent.setBackground(Color.pink);
fmlg.getContentPane().add(pContent);//把面板添加到窗体