再附上一个学生信息输入界面
`package cy;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
@SuppressWarnings(“serial”)
public class StudentLogin extends JFrame implements ActionListener{
JButton jb1=new JButton(“确定”);
JButton jb2=new JButton(“退出”);
JLabel jl1= new JLabel(“学生姓名:”);
JTextField jtf = new JTextField(20);
JLabel jl2= new JLabel(“性 别:”);
// JTextField jpf = new JTextField(20);
String[] listData = new String[]{“男”,“女”};
final JComboBox comboBox = new JComboBox(listData);
public StudentLogin(){
JFrame jf=new JFrame("学生信息输入窗口");
jf.setSize(400, 300);
JPanel mainpanel=new JPanel();
JLayeredPane layeredPane = new JLayeredPane();
layeredPane.setBounds(0, 0, 600, 544);
mainpanel.setBounds(5, 50, 400, 190);
mainpanel.setLayout(new GridLayout(4,1));
// GridLayout layout = new GridLayout(1,2);
// 设置 水平 和 竖直 间隙
// layout.setHgap(10);
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
// JPanel jp3=new JPanel(layout);
JPanel jp3=new JPanel();
Font font = new Font(“黑体”,Font.PLAIN,20);
jl1.setFont(font);
jtf.setFont(font);
jl2.setFont(font);
jp3.setFont(font);
jp1.add(jl1);
jp1.add(jtf);
jp2.add(jl2);
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
// 只处理选中的状态
if (e.getStateChange() == ItemEvent.SELECTED) {
// System.out.println("选中: " + comboBox.getSelectedIndex() + " = " + comboBox.getSelectedItem());
}
}
});
// 设置默认选中的条目
comboBox.setSelectedIndex(0);
// 添加到内容面板
jp2.add(comboBox);
jp3.add(jb1);
jp3.add(jb2);
mainpanel.add(jp1);
mainpanel.add(jp2);
mainpanel.add(jp3);
layeredPane.add(mainpanel);
jf.add(layeredPane);
jf.setLocationRelativeTo(null);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setResizable(false);
jb1.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
message();
}
});
jb2.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
public void message(){
String str= "学生姓名:"+ jtf.getText()+
"; 性别:"+ comboBox.getSelectedItem();
JOptionPane.showMessageDialog(this,str);
}
@SuppressWarnings("unused")
public static void main(String[] args) {
// TODO Auto-generated method stub
StudentLogin Student_Login=new StudentLogin();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
`