帮我写一个java窗口,要求lable放在一个盒子里,textbox放在另一个盒子里,确认按钮和清除按钮放在两个盒子下面,有学号,姓名,邮箱,性别,班级下拉列别,电话,地址;只实现页面布局,不需要实现逻辑
时间: 2023-08-13 14:06:28 浏览: 101
好的,我可以为您提供一个简单的Java窗口布局代码,您可以根据自己的需要进行修改和完善:
```
import java.awt.*;
import javax.swing.*;
public class MyWindow extends JFrame{
private JLabel label1, label2, label3, label4, label5, label6, label7;
private JTextField textField1, textField2, textField3, textField4, textField5;
private JComboBox comboBox;
private JButton button1, button2;
public MyWindow() {
// 设置窗口标题
setTitle("学生信息录入");
// 创建容器
Container container = getContentPane();
container.setLayout(new GridLayout(8, 1));
// 创建组件并添加到容器中
JPanel panel1 = new JPanel();
label1 = new JLabel("学号:");
textField1 = new JTextField(20);
panel1.add(label1);
panel1.add(textField1);
container.add(panel1);
JPanel panel2 = new JPanel();
label2 = new JLabel("姓名:");
textField2 = new JTextField(20);
panel2.add(label2);
panel2.add(textField2);
container.add(panel2);
JPanel panel3 = new JPanel();
label3 = new JLabel("邮箱:");
textField3 = new JTextField(20);
panel3.add(label3);
panel3.add(textField3);
container.add(panel3);
JPanel panel4 = new JPanel();
label4 = new JLabel("性别:");
JRadioButton radioButton1 = new JRadioButton("男");
JRadioButton radioButton2 = new JRadioButton("女");
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(radioButton1);
buttonGroup.add(radioButton2);
panel4.add(label4);
panel4.add(radioButton1);
panel4.add(radioButton2);
container.add(panel4);
JPanel panel5 = new JPanel();
label5 = new JLabel("班级:");
String[] classes = {"一班", "二班", "三班", "四班"};
comboBox = new JComboBox(classes);
panel5.add(label5);
panel5.add(comboBox);
container.add(panel5);
JPanel panel6 = new JPanel();
label6 = new JLabel("电话:");
textField4 = new JTextField(20);
panel6.add(label6);
panel6.add(textField4);
container.add(panel6);
JPanel panel7 = new JPanel();
label7 = new JLabel("地址:");
textField5 = new JTextField(20);
panel7.add(label7);
panel7.add(textField5);
container.add(panel7);
JPanel panel8 = new JPanel();
button1 = new JButton("确认");
button2 = new JButton("清除");
panel8.add(button1);
panel8.add(button2);
container.add(panel8);
// 设置窗口大小
setSize(400, 400);
// 设置窗口可见
setVisible(true);
// 设置窗口关闭方式
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyWindow();
}
}
```
这个窗口布局中包含了您需要的所有组件,可以通过修改和调整来达到您的需求。
阅读全文