⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addstudent.java

📁 学生选课管理系统
💻 JAVA
字号:
package main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import db.StudentinformationBiz;
import entity.Student;

public class AddStudent extends JFrame implements ActionListener{
	JLabel jbstuid;
	JLabel jbstuname;
	JLabel jbclassid;
	JLabel jbnation;
	JTextField jtstuid;
	JTextField jtstuname;
	JComboBox jtclassid;
	JTextField jtnation;
	JButton jenter;
	JButton jcancle;

	public AddStudent(){
		this.setLayout(null);
		jbstuid=new JLabel("学号");
		jbstuname=new JLabel("姓名");
		jbclassid=new JLabel("班级");
		jbnation=new JLabel("民族");
		jtstuid=new JTextField();
		jtstuname=new JTextField();		
		jtnation=new JTextField();
		jtclassid=new JComboBox();
		jenter=new JButton("添加");
		jcancle=new JButton("取消");
		getClassId();
		init1();		

	}
	private void getClassId() {
		StudentinformationBiz db=new StudentinformationBiz();
		String sql="select classname from classname";
		ResultSet rs=db.getInformation(sql);
		try{
			while(rs.next()){
				this.jtclassid.addItem(rs.getString("classname"));
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
	}
	private void init1() {
		this.setTitle("添加学生信息");
		this.setSize(400,300);
		this.setLocationRelativeTo(this);
		this.setVisible(true);
		this.setResizable(false);
		this.add(jbstuid);
		this.jbstuid.setBounds(20, 20, 40, 30);
		this.add(jtstuid);
		this.jtstuid.setBounds(70,20,65,30);
		this.add(jbclassid);
		this.jbclassid.setBounds(160,20,40,30);
		this.add(jtclassid);
		this.jtclassid.setBounds(210,20,65,30);
		this.add(jbnation);
		this.jbnation.setBounds(20,60,40,30);
		this.add(jtnation);	
		this.jtnation.setBounds(70,60,65,30);
		this.add(jbstuname);
		this.jbstuname.setBounds(160,60,40,30);
		this.add(jtstuname);			
		this.jtstuname.setBounds(210,60,65,30);
		this.add(jenter);
		this.jenter.setBounds(100,100,60,30);
		this.jenter.addActionListener(this);
		this.add(jcancle);
		this.jcancle.setBounds(170,100,60,30);
		this.jcancle.addActionListener(this);

		
	}
	public void actionPerformed(ActionEvent arg0) {
		String s=arg0.getActionCommand();
		if(s.equals("取消")){
			this.jtnation.setText("");
			this.jtstuid.setText("");
			this.jtstuname.setText("");

		}else{
			Student stu=new Student();
			StudentinformationBiz db=new StudentinformationBiz();
			int classid=0;
			String classname=(String)this.jtclassid.getSelectedItem();
			String sql="select * from classname where classname='"+classname+"'";
			ResultSet rs=db.getInformation(sql);
			try{
				while(rs.next()){
					classid=rs.getInt("classid");
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			stu.setClassid(classid);
			stu.setNation(this.jtnation.getText());
			stu.setStu_ID(this.jtstuid.getText());
			stu.setStu_name(this.jtstuname.getText());
			
			stu.add();
			this.jtnation.setText("");
			this.jtstuid.setText("");
			this.jtstuname.setText("");
		}
	}
	public static void main(String []args){
		new AddStudent();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -