?? hsystem.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 + -