JFrame jframe = new JFrame(); //创建一个窗口 jframe.setVisible(true) //设置窗口显示 jframe.setLocation() //设置窗口位置 jframe.setSize() // 设置窗口大小
JButton btn = new JButton("确定"); //创建一个确定按钮 jframe.add(btn); //将按钮放入窗口中
JLabel jblName = new JLabel("姓名")
JTextField txtName = newJTextField(20); //参数设置框的大小 JPasswordField txtpwd = new JPasswordField(20);
JFrame默认的布局管理器BorderLayout
BorderLayout分东南西北中 例如:
jframe.add(btn,BorderLayout.WEST); //西布局 jframe.add(btn1,BorderLayout.EAST); //东布局
jframe.setLayout(null) //取消默认布局,完全自定义布局
jframe.setLayout(new FlowLayout());
jframe.setLayout(new GridLayout());
jfame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(); this.add(panel,BorderLayout.NORTH)
pack(); //pack是打包的意思,这里是让窗口里面的控件更加紧凑 this.setResizeable(false) //设置不能再重新定义窗口大小
btnLgin.addActionListener(new ActionListener(){ System.out.print("啊啊啊"); });
JOptionPane.showMessageDialog(null,"登录成功"); //null表示窗口弹出的位置在屏幕中间, 第二个参数是要显示的信息 dispose(); //隐藏窗口
JComboBox combox =new JComboBox(); //设置下拉菜单 String str =(String )combox.getSelectedItem(); //获取选的那一项
如果直接往下拉菜单放入对象,默认下拉菜单显示的是对象的toString方法
JRadioButton rbl =new JRadioButton(" ");
ButtGroup bg = new ButtGroup(); bg.add(rb1); //单选按钮放入按钮组中
原文:https://www.cnblogs.com/zhuhaorong/p/12038679.html