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

📄 zhuce.java

📁 该项目的开发是在学生课程日益增多的压力下设计且用来解决选课的烦恼
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class zhuce extends JFrame implements ActionListener
{
   JTextField userid1 ,userpass1,userpower;
   JButton zhuce1,chong1,tuichu,tianxie;
   Connection con;
   ResultSet rs;
   Statement st;
   String useru=new String();
   String passu=new String();  
   String power=new String(); 
  
   public void zhuce()
   {
    userid1=new JTextField(10);
    userpass1=new JTextField(10);
    userpower=new JTextField(10);
    zhuce1=new JButton("注册");
    zhuce1.addActionListener(this);
   
    chong1=new JButton("重置");
    chong1.addActionListener(this);

    tuichu=new JButton("退出");
    tuichu.addActionListener(this);
    
    tianxie=new JButton("填写个人信息");
    tianxie.addActionListener(this);
   
   
   
    Box box1=Box.createHorizontalBox();
    box1.add(new JLabel("用户名:",JLabel.CENTER));
    box1.add(userid1);
    Box box2=Box.createHorizontalBox();
    box2.add(new JLabel("密    码: ",JLabel.CENTER));
    box2.add(userpass1);
    Box box3=Box.createHorizontalBox();
    box3.add(new JLabel("权    限:",JLabel.CENTER));
    box3.add(userpower);
    Box box4=Box.createHorizontalBox();
    box4.add(new JLabel("注:请填写用户名和学号一直!",JLabel.CENTER));
    Box boxH=Box.createVerticalBox();
    boxH.add(box1);
    boxH.add(box2);
    boxH.add(box3);
    boxH.add(box4);
    boxH.add(Box.createVerticalGlue());


    JPanel pCenter=new JPanel();
    pCenter.add(boxH);
    setLayout(new BorderLayout());
    add(pCenter,BorderLayout.CENTER);
    JPanel pSouth=new JPanel();
    pSouth.add(zhuce1);
    pSouth.add(chong1);
    pSouth.add(tianxie);
    pSouth.add(tuichu);
    add(pSouth,BorderLayout.SOUTH);
    setVisible(true);
    setBounds(100,50,400,300);
    validate();
    }
    
    public void actionPerformed(ActionEvent e)
     {
      if(e.getSource()==zhuce1)
       {
        String usershu=new String();
        usershu=userid1.getText();
        String passshu=new String();
        passshu=userpass1.getText();
        String userpower1=new String();
        userpower1=userpower.getText();
        int count=0;
        if(usershu.length()>0)
          {
           try{//连接数据库
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              }
              catch(ClassNotFoundException e2)
                 {
                            System.out.println(""+e2);
                 }
            try{
                con=DriverManager.getConnection("jdbc:odbc:lhm","","");
                st=con.createStatement();
                rs=st.executeQuery("Select * FROM denglu");
               }
                catch(SQLException el){}//连接数据库
            try{
                  while(rs.next())//判断用户名是否存在
                   {      
                         useru=rs.getString("userid");
                         if(usershu.equals(useru)){count++;}
                   }
                    
                  if(count==0)
                  {String strSQL6 ="insert into denglu(userid,userpassword,userpower) values('" + usershu + "','" + passshu + "','" + userpower1+"')";                  
                   try
                   {
                    st.executeUpdate(strSQL6);
                   }
                   catch(Exception exx){}
                   JOptionPane.showMessageDialog(null,"注册成功!");
                   
                  try
                  {
                   st.close();
                   con.close();
                  }
                  catch(SQLException e3 )
                  {
                  JOptionPane.showMessageDialog(null,"数据库关闭失败!");
                  }

                  }
                 if(count>0) {JOptionPane.showMessageDialog(null,"用户名已存在!");}
               }catch(Exception ee){}
              }
             }
           if(e.getSource()==chong1)
           { 
             userid1.setText("");
             userpass1.setText("");
             userpower.setText("");
           }
            
           if(e.getSource()==tuichu)
           {setVisible(false);}

           if(e.getSource()==tianxie)
           {gerenxinxi grxx=new gerenxinxi();
            grxx.setBounds(200,150,100,100);
            grxx.gerenxinxi();
            grxx.setVisible(true);}
              }

      
       
}

⌨️ 快捷键说明

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