📄 loginjdialog.java
字号:
/* * LoginJDialog.java * * Created on 2009年1月11日, 下午6:49 */package passengertransportmis;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import org.jdesktop.application.Action;/** * * @author Degree41 */public class LoginJDialog extends javax.swing.JDialog { /** Creates new form LoginJDialog */ public LoginJDialog(java.awt.Frame parent, boolean modal,String []args) { super(parent, modal); initComponents(); this.args = args; } @Action public void confirm() { if(this.useridTextField.getText().isEmpty()){ javax.swing.JOptionPane.showMessageDialog(this, "请输入用户编号!", "请输入", 2/*warning*/); return; } if(this.passwordField.getText().isEmpty()){ javax.swing.JOptionPane.showMessageDialog(this, "请输入用户密码!", "请输入", 2/*warning*/); return; } if(this.passwordField.getText().equals(password)){ String[] userInfo = new String[3]; userInfo[0] = this.useridTextField.getText(); userInfo[1] = this.username; userInfo[2] = this.password; PassengerTransportMISApp.setUserInfo(userInfo); PassengerTransportMISApp.setRole(role); PassengerTransportMISApp.Main(args); this.dispose(); }else{ javax.swing.JOptionPane.showMessageDialog(this, "密码错误,请重新输入!", "请重新输入", 0/*error*/); } return; } @Action public void cancel() { this.dispose(); System.exit(0); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); useridTextField = new javax.swing.JTextField(); usernameTextField = new javax.swing.JTextField(); passwordField = new javax.swing.JPasswordField(); confirmButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(passengertransportmis.PassengerTransportMISApp.class).getContext().getResourceMap(LoginJDialog.class); setTitle(resourceMap.getString("Form.title")); // NOI18N setName("Form"); // NOI18N jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N jLabel2.setName("jLabel2"); // NOI18N jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N jLabel3.setName("jLabel3"); // NOI18N useridTextField.setHorizontalAlignment(javax.swing.JTextField.LEFT); useridTextField.setName("useridTextField"); // NOI18N useridTextField.setNextFocusableComponent(passwordField); useridTextField.setVerifyInputWhenFocusTarget(false); useridTextField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { try { if(useridTextField.getText().isEmpty()){ useridTextFieldFocusLost(evt); }else{ useridTextFieldFocusLost(evt,true); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); usernameTextField.setText(resourceMap.getString("usernameTextField.text")); // NOI18N usernameTextField.setText(resourceMap.getString("usernameTextField.text")); // NOI18N usernameTextField.setEnabled(false); usernameTextField.setName("usernameTextField"); // NOI18N passwordField.setText(resourceMap.getString("passwordField.text")); // NOI18N passwordField.setName("passwordField"); // NOI18N javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(passengertransportmis.PassengerTransportMISApp.class).getContext().getActionMap(LoginJDialog.class, this); confirmButton.setAction(actionMap.get("confirm")); // NOI18N confirmButton.setText(resourceMap.getString("confirmButton.text")); // NOI18N confirmButton.setName("confirmButton"); // NOI18N cancelButton.setAction(actionMap.get("cancel")); // NOI18N cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N cancelButton.setName("cancelButton"); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(confirmButton) .addGap(36, 36, 36) .addComponent(cancelButton)) .addGroup(layout.createSequentialGroup() .addGap(43, 43, 43) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(useridTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(61, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {passwordField, useridTextField, usernameTextField}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(45, 45, 45) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(useridTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(17, 17, 17) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(confirmButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cancelButton)) .addContainerGap(39, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cancelButton, confirmButton, jLabel1, jLabel2, jLabel3, passwordField, useridTextField, usernameTextField}); pack(); }// </editor-fold> private void useridTextFieldFocusLost(java.awt.event.FocusEvent evt) { } private void useridTextFieldFocusLost(java.awt.event.FocusEvent evt, boolean bool) throws SQLException {//重载仅为处理此情况:当初次打开直接要点击取消时,id框失去焦点会触发FocusLost() // TODO add your handling code here: Connection conn = Database.getConn(); Statement stmt = Database.createStmt(conn); ResultSet rs = null; String userid = this.useridTextField.getText(); String sql = new String("select * from user where id = '" + userid + "';"); rs = stmt.executeQuery(sql); if(!rs.first()) { javax.swing.JOptionPane.showMessageDialog(this, "该用户不存在,请检查输入的用户编号是否正确!", "请重新输入", 0/*error*/); this.useridTextField.setText(""); return; } userid = rs.getString(1).toString(); username = rs.getString(2); this.usernameTextField.setText(username); password = rs.getString(3); role = rs.getShort(5); } /** * @param args the command line arguments */ public static void main(final String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { LoginJDialog dialog = new LoginJDialog(new javax.swing.JFrame(), true, args); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton cancelButton; private javax.swing.JButton confirmButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPasswordField passwordField; private javax.swing.JTextField useridTextField; private javax.swing.JTextField usernameTextField; // End of variables declaration String []args = null; String userid; String username; String password; short role;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -