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

📄 manager.java

📁 学生管理系统.对学生信息管理的一个应用软件!
💻 JAVA
字号:
import java .awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.border.*;
import javax.swing.*;
import javax.swing.JOptionPane;;
class Mypanel extends Panel implements ActionListener
{  Button sureButton,chargeButton;
   Box baseBox,boxV1,boxV2,boxV3;
   Label userLabel,pswLabel,repswLabel;
   TextField noText,pswordText,repswText;
   Mypanel()
   {    
	    userLabel=new Label("用户名",Label.LEFT);
	    pswLabel=new Label("密码",Label.LEFT);
	    repswLabel=new Label("重置密码",Label.LEFT);
	    noText=new TextField(10);
	    pswordText=new TextField(10);
	    pswordText.setEchoChar('*');
	    repswText=new TextField(10);
	    repswText.setEchoChar('*');
	    boxV1=Box.createVerticalBox();
		boxV1.add(userLabel);
	    boxV1.add(Box.createVerticalStrut(8));
	    boxV1.add(pswLabel);
	    boxV1.add(Box.createVerticalStrut(8));
	    boxV1.add(repswLabel);
		  
		  
	    boxV2=Box.createVerticalBox();
	    boxV2.add(noText);
	    boxV2.add(Box.createVerticalStrut(8));
	    boxV2.add(pswordText);
	    boxV2.add(Box.createVerticalStrut(8));
	    boxV2.add(repswText);
	    
	    baseBox=Box.createHorizontalBox();
	    baseBox.add(boxV1);
		baseBox.add(Box.createHorizontalStrut(10));
		baseBox.add(boxV2);
		 
		add(baseBox);
	    noText.addActionListener(this);
	    pswordText.addActionListener(this);
	    repswText.addActionListener(this);
		 
   }
   public void actionPerformed(ActionEvent e)
   { 
	   
   }
	
}

class managerWindow extends JFrame implements ActionListener
{  Button addButton,resetButton,delButton;
   Mypanel panel1;
   managerWindow(String s)
   {   super(s);
       setLayout(new FlowLayout());
	   panel1=new Mypanel();
       addButton=new Button("添加");
       resetButton=new Button("修改");
       delButton=new Button("删除");
       
       addButton.addActionListener(this);
       resetButton.addActionListener(this);
       delButton.addActionListener(this);
       
       add(addButton);
       add(resetButton);
       add(delButton);
       add(panel1);
       this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
       setBounds(120,120,300,300);
       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 name,key,newkey,addstr,recode;
			   name=panel1.noText.getText();
			   key=panel1.pswordText.getText();
			   newkey=panel1.repswText.getText();
	   	   	 	
			   addstr="INSERT INTO login VALUES ('"+name+"','"+key+"')";
			   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 name,key,newkey,updatestr,recode;
   				name=panel1.noText.getText();
   				key=panel1.pswordText.getText();
   				newkey=panel1.repswText.getText();
   	   	 	
   				updatestr="UPDATE login SET password = '" + newkey+ "' WHERE name='" + name + "'";
   				System.out.println(updatestr);
   				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 name,key,newkey,delstr,recode;
   				name=panel1.noText.getText();
   				key=panel1.pswordText.getText();
   				newkey=panel1.repswText.getText();
   	   	 	
   				delstr="DELETE FROM login WHERE name = '" + name+ "'";
   				System.out.println(delstr);
   				sql.executeUpdate(delstr);
   				con.close();
   			}catch(SQLException ee){
   				System.out.print(ee);
   			}
	   }
	   
   }
	
}

/*public class Manager
{   public static void main(String args[])
  { managerWindow win=new managerWindow("系统管理");
	
  }
}*/

⌨️ 快捷键说明

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