java_swing基础

来源:互联网 发布:如何进行网络视频直播 编辑:程序博客网 时间:2024/05/21 06:34

在我们进行布局的时候,画好画布之后定义部件,然后通过Box进行装载,最后画布装载box,并且一定把setVisiable(true);放在程序的最后


package test;import java.awt.Container;import java.awt.FlowLayout;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;public class test extends JFrame{public test(String str){this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);this.setSize(300, 200);this.setLocation(300, 200);this.setTitle(str);this.setLayout(new FlowLayout());String[] str1 = {"属性","信息"};Object[][] str2 = {{"姓名",""},{"职工号",""},{"身份证号",""},{"性别",""},{"出生年月",""}};JTable table  = new JTable(str2,str1);JButton jb1 = new JButton("修改");JButton jb2 = new JButton("提交");JLabel lable = new JLabel("用户信息",JLabel.CENTER);JScrollPane jsp = new JScrollPane(table);Box b1 = Box.createHorizontalBox();Box b2 = Box.createVerticalBox();b1.add(jb1);b1.add(jb2);b2.add(lable);b2.add(table);b2.add(b1);add(b2);}public static void main(String[] args)  {test jf = new test("我的窗体");jf.setVisible(true);}}


0 0
原创粉丝点击