?? oplogin.java
字號:
package collegems;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.sql.*;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import dbcon.*;
public class OpLogin extends JDialog {
private JPasswordField passwordField;
private JTextField textField;
private JButton button;
private JButton button_1;
JFrame jframe;
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
final OpLogin dialog = new OpLogin();
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
dialog.button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
dialog.button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ResultSet rs=null;
try{
DbCon db=new DbCon();
String sql="select * from user where username='"+dialog.textField.getText()+"' and password='"+(new String(dialog.passwordField.getPassword()))+"'";
rs=db.QueryDb(sql);
if(rs.next())
{
JOptionPane.showMessageDialog(null, "登錄系統成功!");
dialog.dispose();
MainFrame window = new MainFrame();
window.frame.setVisible(true);
db.con.close();
System.out.println("連接關閉!");
}
else
{JOptionPane.showMessageDialog(null, "輸入的用戶或口令錯誤,請重新輸入!");
dialog.textField.setText(null);
dialog.passwordField.setText(null);
}
}catch(SQLException e1){
e1.printStackTrace();
}
//dialog.dispose();
}
});
dialog.setVisible(true);
}catch(Exception e2){
e2.printStackTrace();
}
}
/**
* Create the dialog
*/
public OpLogin() {
super();
getContentPane().setLayout(null);
setTitle("用戶登錄");
setBounds(100, 100, 285, 213);
final JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBounds(17, 21, 250, 149);
getContentPane().add(panel);
final JLabel label = new JLabel();
label.setBounds(10, 21, 58, 18);
label.setText("用戶名:");
panel.add(label);
textField = new JTextField();
textField.setBounds(74, 19, 138, 22);
panel.add(textField);
final JLabel label_1 = new JLabel();
label_1.setText("口 令:");
label_1.setBounds(10, 59, 58, 18);
panel.add(label_1);
passwordField = new JPasswordField();
passwordField.setBounds(74, 57, 138, 22);
panel.add(passwordField);
button = new JButton();
button.setText("登錄");
button.setBounds(10, 105, 106, 28);
panel.add(button);
button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
}
});
button_1.setText("退出");
button_1.setBounds(139, 105, 106, 28);
panel.add(button_1);
//
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -