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

📄 studentui.java

📁 一个简单的选课系统的源代码,本人的数据库课程的作品.数据库用的是db2
💻 JAVA
字号:
package Student;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;


public class StudentUI extends JFrame{
/*	public static void main(String[] args)
	{
		StudentUI x=new StudentUI();
	}*/

	Container cp=getContentPane();
	String ID;
	String key;
	JButton b1=new JButton();
	JButton b2=new JButton();
	JButton b3=new JButton();
	JButton b4=new JButton();
	JButton b5=new JButton();
	JButton b6=new JButton();
	JButton b7=new JButton();
	JButton b8=new JButton();
	JLabel state=new JLabel();
	JPanel jp1=new JPanel();
	Vector v1=new Vector();
	Vector v2=new Vector();
	ResultSet rs;
	
	JScrollPane jsp=new JScrollPane();
	JTable jtb;
	public StudentUI(String IDt,String keyt)
	{
		
		try{
			jbinit(IDt,keyt);
		}catch(Exception ex){ex.printStackTrace();}
	}
	public void jbinit(String ID,String key)
	{
		this.ID=ID;
		this.key=key;
		b1.setText("查询可选课程");
		b1.setForeground(Color.BLUE);
		b1.setFont(new Font("SansSerif", Font.PLAIN, 12));
		b1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e)
			{
				try{
					v1.removeAllElements();
					v2.removeAllElements();
					v2.add("课程号");
					v2.add("课程名");
					v2.add("教师");
					v2.add("学分");
					v2.add("上课教室");
					MyJDBC k=new MyJDBC();
					ResultSet rs=k.exceteQuery("select * from wengxinzhi.studentcourseview");
					while(rs.next())
					{
						Vector v3=new Vector();
						v3.add(rs.getString(1));
						v3.add(rs.getString(2));
						v3.add(rs.getString(3));
						int temp=rs.getInt(4);
						v3.add(Integer.toString(temp));
						v3.add(rs.getString(5));
						v1.add(v3);
						System.out.println(v1);
					}
					rs.close();
					System.out.println(v2);
					jtb=new JTable(v1,v2);
					jsp.getViewport().add(jtb,null);
				}catch(Exception o){o.printStackTrace();}
			}
		});
		
		
		
		b2.setText("查询成绩");
		b2.setForeground(Color.BLUE);
		b2.setFont(new Font("SansSerif", Font.PLAIN, 12));
		class InsaltResult implements ActionListener {
			String ID;
				public InsaltResult(String IDS) {
					ID=IDS;
				}

				public void actionPerformed(ActionEvent e) {
					try {
						v1.removeAllElements();
						v2.removeAllElements();
						v2.add("学号");
						v2.add("学生姓名");
						v2.add("课程号");
						v2.add("课程名");
						v2.add("成绩");
						MyJDBC k = new MyJDBC();
						ResultSet rs = k
								.exceteQuery("select * from wengxinzhi.studentscoreview where 学号='"
										+ ID + "'");

						while (rs.next()) {
							Vector v3 = new Vector();
							v3.add(rs.getString(1));
							v3.add(rs.getString(2));
							v3.add(rs.getString(3));
							v3.add(rs.getString(4));
							int temp = rs.getInt(5);
							v3.add(Integer.toString(temp));

							v1.add(v3);
							System.out.println(v1);
						}
						rs.close();
						System.out.println(v2);
						jtb = new JTable(v1, v2);
						jsp.getViewport().add(jtb, null);
					} catch (Exception o) {
						o.printStackTrace();
					}
				}
			}
		b2.addActionListener(new InsaltResult(ID));

		
		
		b3.setText("选修课程");
		b3.setForeground(Color.BLUE);
		b3.setFont(new Font("SansSerif", Font.PLAIN, 12));
		class SelectCourse implements ActionListener
		{
			String ID;
			public SelectCourse(String id)
			{
				ID=id;
			}
			public void actionPerformed(ActionEvent e)
			{
				try{
					StudentSelect p=new StudentSelect(ID);
				}catch(Exception o){o.printStackTrace();}
			}
		}
		b3.addActionListener(new SelectCourse(ID));
		b4.setText("修改个人信息");
		b4.setForeground(Color.BLUE);
		b4.setFont(new Font("SansSerif", Font.PLAIN, 12));
		class UpdataSData implements ActionListener
		{
			String ID;
			public UpdataSData(String IDt)
			{
				ID=IDt;
			}
			public void actionPerformed(ActionEvent e)
			{
				Updata x=new Updata(ID);
			}
		}
		b4.addActionListener(new UpdataSData(ID));
		b6.setText("退出系统");
		b6.setForeground(Color.BLUE);
		b6.setFont(new Font("SansSerif", Font.PLAIN, 12));
		b6.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e)
			{
				dispose();
				System.exit(0);
			}
		});
		b5.setText("个人信息");
		b5.setForeground(Color.BLUE);
		b5.setFont(new Font("SansSerif", Font.PLAIN, 12));
		class Personal implements ActionListener
		{
			String ID;
			public Personal(String IDt)
			{
				ID=IDt;
			}
			public void actionPerformed(ActionEvent e) {
				try {
					v1.removeAllElements();
					v2.removeAllElements();
					v2.add("学号");
					v2.add("姓名");
					v2.add("年龄");
					v2.add("性别");
					v2.add("院系编号");
					MyJDBC k = new MyJDBC();
					ResultSet rs = k
							.exceteQuery("select sid,name,age,sex,dep from wengxinzhi.student where sid='"
									+ ID + "'");

					while (rs.next()) {
						Vector v3 = new Vector();
						v3.add(rs.getString(1));
						v3.add(rs.getString(2));
						v3.add(Integer.toString(rs.getInt(3)));
						v3.add(rs.getString(4));
						v3.add(Integer.toString(rs.getInt(5)));

						v1.add(v3);
						System.out.println(v1);
					}
					System.out.println(v2);
					jtb = new JTable(v1, v2);
					jsp.getViewport().add(jtb, null);
				} catch (Exception o) {
					o.printStackTrace();
				}
			}
		}
		b5.addActionListener(new Personal(ID));
		b7.setText("查询可选课程");
		b7.setForeground(Color.BLUE);
		b7.setFont(new Font("SansSerif", Font.PLAIN, 20));
		b8.setText("查询可选课程");
		b8.setForeground(Color.BLUE);
		b8.setFont(new Font("SansSerif", Font.PLAIN, 20));
		jp1.add(b1);
		jp1.add(b2);
		jp1.add(b3);
		jp1.add(b5);
		jp1.add(b4);
		jp1.add(b6);
		cp.setLayout(new BorderLayout());
		cp.add(jp1,BorderLayout.NORTH);
		cp.add(jsp,BorderLayout.CENTER);
		this.setSize(600,450);

		this.setTitle("学生选课系统");
		this.setLocation(200,200);
		this.setVisible(true);
	}
}

⌨️ 快捷键说明

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