?? windowlogin.java
字號:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.event.*;
import java.sql.*;
class WindowLogin extends JFrame implements ActionListener
{
Connection con=null;
Statement sta=null;
JLabel l,l1,l2;
JButton b1,b2;
JTextField tf1;
JPasswordField tf2;
TextField ff;
String conURL="jdbc:mysql://localhost/login?user=root&password=root";
ResultSet rs;
WindowLogin()
{
super("系統登入界面");
setBounds(150,150,400,300);
setLayout(null);
this.setResizable(false);
l=new JLabel();
l.setText( "歡迎登陸宿舍信息管理系統" );
l.setFont( new Font("Dialog", 1, 25));
l.setForeground( new Color(255, 144, 85 ) );
l.setHorizontalAlignment(SwingConstants.CENTER);
l.setBounds(20,20,350,40);
add(l);
l1=new JLabel("用戶名:");
l1.setForeground(Color.black);
l1.setFont(new Font("Dialog", 1, 20));
l1.setBounds(70,90,80,30);
add(l1);
l2=new JLabel("密 碼:");
l2.setForeground(Color.black);
l2.setFont(new Font("Dialog", 1, 20));
l2.setBounds(70,120,80,30);
add(l2);
tf1=new JTextField(20);
tf1.setBounds(150,90,140,30);
add(tf1);
tf2=new JPasswordField();
tf2.setBounds(150,120,140,30);
add(tf2);
b1=new JButton("登陸");
b1.setBounds(70,160,100,40);
add(b1);
b2=new JButton("重置");
b2.setBounds(190,160,100,40);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
ConSql();
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
LogIn();
}
else if(e.getSource()==b2)
{
tf1.setText("");
tf2.setText("");
}
}
public void LogIn()
{
String str1=tf1.getText().trim();
String str2=tf2.getText().trim();
try{
con=DriverManager.getConnection(conURL);
rs=sta.executeQuery("select * from login");
while(rs.next())
{
String user1=rs.getString("user").trim();
// String pwd=rs.getString("pwd").trim();
if(user1.equals(str1))
{
String pwd1=rs.getString("pwd").trim();
if(pwd1.equals(str2))
{
System.out.println("用戶登入成功!");
rs.close();
sta.close();
con.close();
this.dispose();
new Window();
break;
}
else{
System.out.println("密碼錯誤");
new JOptionPane().showMessageDialog(null, "密碼錯誤或者用戶不存在。");
break;
}
}
}
}
catch(SQLException e1)
{
e1.printStackTrace();
}
}
public void ConSql()
{
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection(conURL);
sta=con.createStatement();
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -