add(p1,BorderLayout.NORTH); Box box[]=new Box[3]; for(int i=0;i<3;i++){ box[i]=Box.createVerticalBox(); } box[0].add(new Label(\课程名称\ box[1].add(new Label(\删课\ panel=new Panel(); Box basebox=Box.createHorizontalBox(); basebox.add(box[0]); basebox.add(Box.createHorizontalStrut(8)); basebox.add(box[1]); panel.add(basebox); add(panel,BorderLayout.CENTER); setBounds(200,200,500,300); addWindowListener(new WindowAdapter() {// 关闭程序时的操作 public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); int n=0; String s_name,s_id, c_name,c_id; try{ Connection conn=GetConnection.getConnection(); PreparedStatement sql=conn.prepareStatement(\count(cno) FROM xuanke WHERE sno=\ ResultSet rs=sql.executeQuery(); while(rs.next()){ n=rs.getInt(1); } l1=new Label[n]; l2=new Label[n]; l3=new Label[n]; int N=0; PreparedStatement sql1=conn.prepareStatement(\cno FROM xuanke
WHERE sno=\ ResultSet rs1=sql1.executeQuery(); while(rs1.next()){ c_id=rs1.getString(1); PreparedStatement sql2=conn.prepareStatement(\cname,c_sy FROM course WHERE cno=\ ResultSet rs2=sql2.executeQuery(); while(rs2.next()){ c_name=rs2.getString(1); l1[N]=new Label(c_name); box[0].add(l1[N]); l3[N]=new Label(rs2.getString(2)); } l2[N]=new Label(c_id); N++; } checkbox2=new Checkbox[n+1]; for(int i=0;i sql1_1=conn.prepareStatement(\ PreparedStatement sql1_3=conn.prepareStatement(\ sql1_3.setInt(1,Integer.parseInt(l3[i].getText())+1); sql1_3.setInt(2, Integer.parseInt(l2[i].getText())); sql1_1.executeUpdate(); sql1_3.executeUpdate(); } } } catch(SQLException e1){ System.out.println(e1); } panel.removeAll(); Button b1=new Button(\删课成功,确定离开\ panel.add(b1); setVisible(true); b1.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { dispose(); } } ); } } ); } catch(SQLException e1){ e1.printStackTrace(); } } } 4、学生系统: import java.sql.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Student extends Frame { Box box1=Box.createVerticalBox(), box2=Box.createVerticalBox(); Student(String xuehao) { setTitle(\学生\ box1.add(new Label(\学号\ box2.add(new Label(\姓名\ Label l1=new Label(xuehao); System.out.println(xuehao); try{ Connection conn=GetConnection.getConnection(); PreparedStatement sql=conn.prepareStatement(\* FROM student where s_id=\ ResultSet rs=sql.executeQuery(); while(rs.next()){ String s_id=rs.getString(\ System.out.println(s_id); String s_name=rs.getString(2); box1.add(new Label(s_id)); box2.add(new Label(s_name)); } Box box=Box.createHorizontalBox(); box.add(box1); box.add(Box.createHorizontalStrut(20)); box.add(box2); //box.add(Box.createHorizontalStrut(10)); removeAll(); setLayout(new FlowLayout()); add(box); } catch(SQLException e1){ System.out.println(e1); } addWindowListener(new WindowAdapter() {// 关闭程序时的操作 public void windowClosing(WindowEvent e) { dispose(); } }); setSize(400,250); setVisible(true); validate(); } } 5、学生选课框架: import java.awt.*; import java.awt.event.*; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.*; class StudentFrame extends Frame implements ActionListener { String xuehao,xingming; Panel p1 = new Panel(); Panel p2 = new Panel(); Button b1 = new Button(\学生信息查看\ Button b2 = new Button(\教师信息查看\ Button b3 = new Button(\选课\ Button b4 = new Button(\删课\ StudentFrame(String username) { super(\学生选课系统\ xuehao=new String(username); setSize(350, 200); p1.setLayout(new FlowLayout()); p2.setLayout(new FlowLayout()); add(\ add(\ try{ Connection conn=GetConnection.getConnection(); PreparedStatement sql=conn.prepareStatement(\* WHERE s_id=\ ResultSet rs=sql.executeQuery(); if(rs.next()){ xingming=rs.getString(\ p1.add(new Label(\学号: \ p1.add(new Label(\姓名: \ } } catch(SQLException e1){ System.out.println(e1); } p2.add(b1); p2.add(b2); p2.add(b3); p2.add(b4); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); addWindowListener(new WindowAdapter() {// 关闭程序时的操作 public void windowClosing(WindowEvent e) { System.exit(0); } }); FROM student 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数据库实验报告(8)在线全文阅读。
相关推荐: