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

📄 hsystem.java

📁 本系统适合中小规模宾馆使用
💻 JAVA
字号:
import javax.swing.*;//GUI
import javax.swing.JOptionPane;
import java.awt.*;

import java.awt.event.*;

import java.sql.*;

import java.util.*;


//密码登陆届面--------------------------------------------------------
class Login extends Frame implements ActionListener
 { TextField text1,text2;
   Label label1,label2,label3;
   Button button1,button2,button3;
   Connection con =null;Statement stmt=null;
   Hotel h;
   Manager man;

   Login( )
   { super("欢迎使用WWW员工管理系统");
    setForeground(Color.blue);
    setBounds(200,200,300,200);
    setVisible(true);
    //setVisble(false);
    h=new Hotel();
    man=new Manager();
    validate();

    text1=new TextField(10);
    text2=new TextField(10);
    label1=new Label("用户名");
    label2=new Label("密码");
    label3=new Label("欢迎使用此系统");
    button1=new Button("登陆");
    button2=new Button("取消");
    button3=new Button("员工");
    setLayout(new BorderLayout());
    Panel p1=new Panel();
    Panel p2=new Panel();

    p1.add(label1);p1.add(text1);
    p1.add(label2);p1.add(text2);
    add(p1,BorderLayout.CENTER);
    p2.add(button1);p2.add(button2);p2.add(button3);
    add(p2,BorderLayout.SOUTH);
    //text1.setText("ysy");
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);

    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
    catch(ClassNotFoundException e){ }
    try{
         con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
         stmt=con.createStatement();
         }
    catch(SQLException ee) { }

    addWindowListener(new WindowAdapter()
                  { public void windowClosing(WindowEvent e)
                     {System.exit(0);}
                     });
                   }

  public void actionPerformed(ActionEvent e)
  {
  	if(e.getSource()==button1)
     try{ log(1);}
     catch(SQLException ee){}

     else if(e.getSource()==button3)
     try{ log(3);}
     catch(SQLException ee){}
  
     else if(e.getSource()==button2)
       {text1.setText(null);
        text2.setText(null);}
   }

   public void log(int f) throws SQLException
    { boolean right=true;
      String name ,ma;
      con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
      ResultSet rs=stmt.executeQuery("select * from users");
      while(rs.next())
        { name=rs.getString("用户名");
          ma=rs.getString("密码");
          if(name.equals(text1.getText())&&ma.equals(text2.getText()))
            { JOptionPane.showMessageDialog(this,"欢迎进入该系统!","警告",JOptionPane.WARNING_MESSAGE);
              setVisible(false);
              if(f==1) h.setVisible(true);
              else if(f==3) man.setVisible(true);
              right=false;
               }
      }
           if(right)
             {
              JOptionPane.showMessageDialog(this,"输入错误","警告",JOptionPane.WARNING_MESSAGE);
              text1.setText(null);
              text2.setText(null);
             }
              
         con.close();
      }
  }


  //主函数=======================================================
   public class HSystem
  {public static void main(String args[])
   {
     Login window=new Login();window.pack();

   }
  }

⌨️ 快捷键说明

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