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

📄 coursemanagement.java

📁 这个是我二年级写的一个教务管理系统 大家可以下来
💻 JAVA
字号:
// StudentFrame21.java

package caoyu;//选课管理系统

import javax.swing.table.AbstractTableModel;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

 class CourseManagement extends JFrame {
	
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  //JLabel jLabel4 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JLabel jLabel6 = new JLabel();
  JLabel jLabel7 = new JLabel();
  
  ButtonGroup bg = new ButtonGroup();
  JRadioButton jRadioButton1 = new JRadioButton();
  JRadioButton jRadioButton2 = new JRadioButton();
  
  JTextField jTextField1 = new JTextField();
  JTextField jTextField2 = new JTextField();
  JTextField jTextField3 = new JTextField();
  JTextField jTextField4 = new JTextField();
  JTextField jTextField5 = new JTextField();
  
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  JButton jButton4 = new JButton();

  public CourseManagement() {
     try {
        jbInit();
     }
     catch(Exception ex) {
        ex.printStackTrace();
     }
  }

  public void jbInit() throws Exception {
  	 Container container = this.getContentPane();
  	 container.setLayout(null);
  	 
     jLabel1.setFont(new java.awt.Font("Dialog", 1, 24));
     jLabel1.setText("选课管理系统");
     jLabel1.setBounds(151, 20, 244, 44);
     jLabel2.setFont(new java.awt.Font("Dialog", 0, 18));
     jLabel2.setText("课程号");
     jLabel2.setBounds(30, 66, 64, 38);
     jLabel3.setFont(new java.awt.Font("Dialog", 0, 18));
     jLabel3.setText("课程名");
     jLabel3.setBounds(280, 67, 64, 38);
     //jLabel4.setFont(new java.awt.Font("Dialog", 0, 18));
    // jLabel4.setText("授课教师编号");
     //jLabel4.setBounds(29, 107, 64, 38);
     //jLabel4.setVerifyInputWhenFocusTarget(true);
     jLabel5.setFont(new java.awt.Font("Dialog", 0, 18));   
     jLabel5.setText("授课教师编号");
     jLabel5.setBounds(29, 160, 110, 38);
     jLabel6.setFont(new java.awt.Font("Dialog", 0, 18));
     jLabel6.setText("学分");
     jLabel6.setBounds(new Rectangle(277, 163, 75, 38));    
     jLabel7.setFont(new java.awt.Font("Dialog", 0, 18));
     jLabel7.setText("学时");
     jLabel7.setBounds(25, 212, 64, 38);
     
     jTextField1.setText("");
     jTextField1.setBounds(112, 73, 131, 24);
     
    /* jRadioButton1.setFont(new java.awt.Font("Dialog", 0, 18));
     jRadioButton1.setText(" 限选 ");
     jRadioButton1.setBounds(122, 117, 73, 19);
     jRadioButton2.setFont(new java.awt.Font("Dialog", 0, 18));
     jRadioButton2.setText(" 必修");
     jRadioButton2.setBounds(232, 117, 73, 19);
     bg.add(jRadioButton1);
     bg.add(jRadioButton2);*/
     
     jTextField2.setText("");
     jTextField2.setBounds(342, 73, 136, 24);
     jTextField3.setText("");
     jTextField3.setBounds(140, 168, 120, 24);
     jTextField4.setText("");
     jTextField4.setBounds(351, 165, 131, 24);
     jTextField5.setText("");
     jTextField5.setBounds(108, 214, 377, 24);
     
     jButton1.setBounds(50, 262, 98, 35);
     jButton1.setFont(new java.awt.Font("Dialog", 0, 16));
     jButton1.setText("添加");
     jButton1.setBorder(BorderFactory.createEtchedBorder());
     jButton1.addActionListener(
     	 new ActionListener() {
     	    public void actionPerformed(ActionEvent event)
     	    {  //一学
     	       Course c = new Course();
               c.cno = jTextField1.getText().trim();
               c.cname = jTextField2.getText().trim();
               //if(jRadioButton1.isSelected())
                 // c.ssex = "限选";
              // else 
                 // c.ssex = "必修";
               c.tno = jTextField3.getText().trim();
               c.credit = jTextField4.getText().trim();
               c.period = jTextField5.getText().trim();
               DBOperatorCourse op = new DBOperatorCourse();
               op.addCourse(c);
               JOptionPane.showMessageDialog(null,"选课成功",
			      "result",JOptionPane.PLAIN_MESSAGE);
			   jTextField1.setText(null);
			   jTextField2.setText(null);
			   jTextField3.setText(null);
			   jTextField4.setText(null);
			   jTextField5.setText(null);	
     	    }	
     	 }
     );
     
     jButton2.setBounds(164, 263, 98, 35);
     jButton2.setFont(new java.awt.Font("Dialog", 0, 16));
     jButton2.setText("查询");
     jButton2.setBorder(BorderFactory.createEtchedBorder());
     jButton2.addActionListener(
     	new ActionListener() {
     	   public void actionPerformed(ActionEvent event)
     	   {  //学呕询一学
     	      ShowQuery show = new ShowQuery();
     	   }
     	}  
     );
     jButton3.setBounds(278, 262, 98, 35);
     jButton3.setFont(new java.awt.Font("Dialog", 0, 16));
     jButton3.setText("删除");
     jButton3.setBorder(BorderFactory.createEtchedBorder());
     jButton3.addActionListener(
     	new ActionListener() {
     	   public void actionPerformed(ActionEvent event)
     	   {  //删一学
     	      if(jTextField2.getText().trim().equals("")) {
     	         JOptionPane.showMessageDialog(null,"请输入名称 ",
			         "WARING",JOptionPane.WARNING_MESSAGE);
	          }
	          else { 
     	         DBOperatorCourse op = new DBOperatorCourse();
     	         op.deleteCourse(jTextField2.getText().trim());
     	         JOptionPane.showMessageDialog(null,"退课成功",
			         "result",JOptionPane.PLAIN_MESSAGE);
			     jTextField2.setText(null);
			  } 	
     	   }	
     	}
     );
     
     jButton4.setBounds(393, 260, 98, 35);
     jButton4.setFont(new java.awt.Font("Dialog", 0, 16));
     jButton4.setText("退出");
     jButton4.setBorder(BorderFactory.createEtchedBorder());
     jButton4.addActionListener(
     	new ActionListener() {
     	   public void actionPerformed(ActionEvent event)
     	   {  //顺
     	      System.exit(0);   	
     	   }	
     	}
     );
     
     container.add(jLabel1, null);
     container.add(jLabel2, null);
     container.add(jTextField1, null);
     container.add(jLabel3, null);
     container.add(jTextField2, null);
    // container.add(jLabel4, null);
     //container.add(jRadioButton1, null);
     //container.add(jRadioButton2, null);
     container.add(jLabel5, null);
     container.add(jTextField3, null);
     container.add(jLabel6, null);
     container.add(jTextField4, null);
     container.add(jLabel7, null);
     container.add(jTextField5, null);
     container.add(jButton1, null);
     container.add(jButton2, null);
     container.add(jButton3, null);
     container.add(jButton4, null);
     
     setSize(510,370);
     setVisible(true);
  }
  public static void main(String args[]) {
     CourseManagement frame = new CourseManagement();
     frame.setSize(510,370);
     frame.setVisible(true);
  }
}

class ShowQuery extends JFrame {
   public JRadioButton cno = null;
   public JRadioButton cname = null;
   public JTextField jt = null;
   public JButton btn = null;
   public JTable table = null;
   public ShowQuery() 
   {
      this.initFrame();
      this.setTitle("选课信息系统");
      setSize(500,300);
      setVisible(true);
  }
  public void initFrame()
  {
     Container container = this.getContentPane();
      String[][] p = new String[100][6];
      String[] n = {"cno","cname","tno","xuefen","xueshi"};
      table = new JTable(p,n);
      JScrollPane s = new JScrollPane(table);
      container.add(s, BorderLayout.CENTER);
      JPanel pnl = new JPanel();
      pnl.setLayout( new GridLayout(1,4) );
      cno = new JRadioButton( "课程名", false );
      cname = new JRadioButton( "课程名", true );
   
      btn = new JButton( "查询" );
      pnl.add( btn );
      jt = new JTextField( 10 );
      pnl.add( jt );
      container.add(pnl, BorderLayout.NORTH);
      btn.addActionListener(
      	 new ActionListener() {
      	    public void actionPerformed(ActionEvent e)
      	    {
      	       try {
      	 	      DBOperatorCourse op = new DBOperatorCourse();
      	 	      ResultSet rs = op.queryCourse(jt.getText().trim());
      	          for(int i=0;rs.next();i++)
					{
						table.setValueAt(rs.getString(1),i,0);
						table.setValueAt(rs.getString(2),i,1);
						table.setValueAt(rs.getString(3),i,2);
						table.setValueAt(rs.getString(4),i,3);
						table.setValueAt(rs.getString(5),i,4);
						//table.setValueAt(rs.getString(6),i,5);
					}
			   rs.close();
               op.conn.close();
               }
               catch(Exception ex) {
                  System.out.println(ex.getMessage());
                  ex.printStackTrace();	
               }
            }
          }
      ); 
  }
}

⌨️ 快捷键说明

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