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

📄 hotel.java

📁 一个java源码的酒店管理系统
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.sql.*;
import javax.swing.*;
public class hotel extends JFrame {  
     
       
       
	JLabel name=new JLabel("用户名:");
  JLabel se=new JLabel("密码:");

    JTextField name1=new JTextField();  //文本框 
   JPasswordField se1=new JPasswordField();
  
      JLabel hint=new JLabel("操作提示");
     JButton zc=new JButton("用户登陆"); //按钮  
                        
public hotel() { 

super("酒店管理系统用户登陆");
   
    setLayout(new GridBagLayout());
        GridBagConstraints gridBag=new GridBagConstraints();
    gridBag.fill=GridBagConstraints.HORIZONTAL;
    gridBag.weightx=0;
    gridBag.weighty=0;
    name.setFont(new Font("Alias",Font.BOLD,16));
     add(name,gridBag,0,0,1,1);

  se.setFont(new Font("Alias",Font.BOLD,16));
     add(se,gridBag,0,1,1,1);



    gridBag.weightx=100;
    gridBag.weighty=0;
  add(name1,gridBag,1,0,2,1);
     
     add(se1,gridBag,1,1,2,1);

  
       add(zc,gridBag,1,2,2,1);
          add(hint,gridBag,1,3,2,1);
      	
       gridBag.fill=GridBagConstraints.BOTH;
       gridBag.weightx=100;
          gridBag.weighty=100;
    setSize(310,180);
   setVisible(true);

     zc.addActionListener(new ActionListener(){
     	
       	public void actionPerformed(ActionEvent e){
       		try
     {
     	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     }catch(java.lang.ClassNotFoundException ex){}  
   	String url="jdbc:odbc:HOTEL";
   	   
   
   try{
   	 Connection con=DriverManager.getConnection(url,"",null);

    Statement stmt=con.createStatement();
   String s1,s2="";
   
   String s=name1.getText();
     String str=se1.getText();
     
    String sql="SELECT * FROM userpassword";

ResultSet rs=stmt.executeQuery(sql);
	 
	while(rs.next()){
	    
	    s1=rs.getString("userid");
		s2=rs.getString("password");
		if(s1.equals(s)==true&&s2.equals(str)==true)
		{
			new test();
		setVisible(false);
		}		
	else hint.setText("密码错误");
		}
		

        
 	 	stmt.close();
		con.close();
	
		}
		catch(SQLException ex){}
           		
           	}      	
}
);
}


public void add(Component c,GridBagConstraints gbc,int x,int y,int w,int h)
{
     gbc.gridx=x;
     gbc.gridy=y;
     gbc.gridheight=h;
     gbc.gridwidth=w;
     add(c,gbc);
}


public static void main(String a[])
{
   new hotel();   
}



}

⌨️ 快捷键说明

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