```java
package testgui;
import javax.swing.*;
@SuppressWarnings(“all”) public class TestGUI {
public static void main(String[] args){//frame 最大的窗体 管理方式边界式 中 东 西 南 北 BorderLayout//JMenuBar 菜单条 上面 frame.setJMenuBar(bar);//Panel 面板 可以有多个 管理方式流式 居中 FlowLayout//组件//frame.setLayOut(new FlowLayout()); frame.setLayout(null);//先创建一个窗体对象JFrame frame = new JFrame("这是我的第一个窗体");//创建一个面板JPanel panel = new JPanel();//创建标签JLabel userLabel = new JLabel("账户:");JLabel passLabel = new JLabel("密码:");//创建一个文本框JTextField text = new JTextField(20);//密码框JPasswordField pass = new JPasswordField(20);//创建一个按钮对象JButton button = new JButton("登录");//button.setText("");//创建复选框JCheckBox box1 = new JCheckBox("抽烟");JCheckBox box2 = new JCheckBox("喝酒");JCheckBox box3 = new JCheckBox("烫头");//创建单选按钮JRadioButton r1 = new JRadioButton("男");JRadioButton r2 = new JRadioButton("女");//将两个单选按钮添加在一个组里面ButtonGroup group = new ButtonGroup();//组本身不是组件group.add(r1);group.add(r2);//创建文本域JTextArea area = new JTextArea(5,20);//滚动条JScrollPane pane = new JScrollPane(area);//菜单条 JMenuBar//菜单 JMenu//菜单项 JMenuItemJMenuBar bar = new JMenuBar();JMenu menu = new JMenu("File");JMenuItem newItem = new JMenuItem("New");menu.add(newItem);bar.add(menu);//将按钮添加在窗体内panel.add(userLabel);panel.add(text);panel.add(passLabel);panel.add(pass);panel.add(button);panel.add(box1);panel.add(box2);panel.add(box3);panel.add(r1);panel.add(r2);panel.add(pane);frame.setJMenuBar(bar);frame.add(panel);//设置窗体的title//frame.setTitle("这是我的第一个窗体");//设置不可以拖拽大小//frame.setResizable(false);//设置窗体出现时的位置和自身的宽高frame.setBounds(500,250,300,150);//设置窗体的状态显示frame.setVisible(true);//设置点击关闭按钮 窗体执行完毕frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
}
```
