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

📄 addcourse.java

📁 学生管理系统.对学生信息管理的一个应用软件!
💻 JAVA
字号:
import javax.swing.*; 
import java.sql.*;
import java.awt.*;

import javax.swing.border.*;
import java.awt.event.*;
import java.sql.DriverManager;
class addcourse1 extends JFrame implements ActionListener
{  Box baseBox,boxV1,boxV2;
   TextField noText,courseText,teacherText;
   Label noLabel,courseLabel,teacherLabel;
   Button addButton,resetButton,delButton;
   JPanel panel=new JPanel();
   addcourse1(String s)
   {  super(s);
      setLayout(new FlowLayout());
      addButton=new Button("添加");
	  resetButton=new Button("修改");
	  delButton=new Button("删除");
      noLabel=new Label("课程号",Label.LEFT);
	  courseLabel=new Label("科目",Label.LEFT);
	  teacherLabel=new Label("教师",Label.LEFT);
	  noText=new TextField(10);
	  courseText=new TextField(10);
	  teacherText=new TextField(10);
	  add(addButton);
      add(resetButton);
      add(delButton);
	  boxV1=Box.createVerticalBox();
	  boxV1.add(noLabel);
	  boxV1.add(Box.createVerticalStrut(5));
	  boxV1.add(courseLabel);
	  boxV1.add(Box.createVerticalStrut(5));
	  boxV1.add(teacherLabel);
	 
	  boxV1.add(Box.createVerticalStrut(8));
	 
	  
	  boxV2=Box.createVerticalBox();
	  boxV2.add(Box.createVerticalStrut(7));
	  boxV2.add(noText);
	  boxV2.add(Box.createVerticalStrut(6));
	  boxV2.add(courseText);
	  boxV2.add(Box.createVerticalStrut(7));
	  boxV2.add(teacherText);
	  boxV2.add(Box.createVerticalStrut(6));
	  
	  baseBox=Box.createHorizontalBox();
	  baseBox.add(boxV1);
	  baseBox.add(Box.createHorizontalStrut(5));
	  baseBox.add(boxV2);
	  
	  
	  setLayout(new FlowLayout());
	  add(baseBox);
	  addButton.addActionListener(this);
	  resetButton.addActionListener(this);
	  delButton.addActionListener(this);
	  
      
      this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	  setBounds(120,120,250,250);
	  setVisible(true);
	  validate();
   }
   public void actionPerformed(ActionEvent e)
   {    
   	if(e.getSource()==addButton)
   	{
 	       Connection con;
		   Statement sql;
		   ResultSet rs;
		   try{
			   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		   }catch(ClassNotFoundException k){
			   System.out.println(""+k);
		   }
		   try{
			   con=DriverManager.getConnection("jdbc:odbc:sun","","");
			   sql=con.createStatement();
			   String no,course,teacher,addstr;
			   no=noText.getText();
			   course=courseText.getText();
			   teacher=teacherText.getText();
	   	   	 	
			   addstr="INSERT INTO 课程信息表 VALUES ('"+no+"','"+course+"','"+teacher+"')";
			   System.out.println(addstr);
			   sql.executeUpdate(addstr);
			   con.close();
		   }catch(SQLException ee){
			   System.out.print(ee);
		   }
 	}
 	if(e.getSource()==resetButton)
 	{
 		    Connection con;
		   	Statement sql;
		   	ResultSet rs;
		   	try{
		   		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		   	}catch(ClassNotFoundException k){
		   		System.out.println(""+k);
		   	}
		   	try{
		   		con=DriverManager.getConnection("jdbc:odbc:sun","","");
			   	sql=con.createStatement();
			    String no,course,teacher,updatestr=null;
			   	no=noText.getText();
			   	course=courseText.getText();
			   	teacher=teacherText.getText();
			
			   	
			   	updatestr="UPDATE 课程信息表 SET courseno='" + no+ "' WHERE course='" + course +"'";
			   	sql.executeUpdate(updatestr);
			   	con.close();
		   	}catch(SQLException ee){
			   System.out.print(ee);
		   	}
 	}
	if(e.getSource()==delButton)
 	{
 		Connection con;
 		Statement sql;
 		ResultSet rs;
 		try{
 			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 		}catch(ClassNotFoundException k){
 			System.out.println(""+k);
 		}
 		try{
 			con=DriverManager.getConnection("jdbc:odbc:sun","","");
 			sql=con.createStatement();
 			String no,delstr;
 			no=noText.getText();
 			delstr="DELETE FROM 课程信息表 WHERE courseno = '" + no+ "'";
 			System.out.println(delstr);
 			sql.executeUpdate(delstr);
 			con.close();
		   	}catch(SQLException ee){
		   		System.out.print(ee);
		   	}
 		}
	   
 	}
}
/*public class addcourse
{
	public static void main(String args[])
	{
		addcourse1 win=new addcourse1("课程更改");
	}
}*/

⌨️ 快捷键说明

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