模拟学生信息输入界面

再附上一个学生信息输入界面在这里插入图片描述
`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
	
}

}
`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值