📄 loginjframe.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. *//* * LogInJFrame.java * * Created on 2009-4-1, 19:57:41 */package logintest;import java.util.logging.Level;import java.util.logging.Logger;import javax.persistence.EntityManager;import javax.persistence.NoResultException;import javax.swing.JOptionPane;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;/** * * @author Administrator */public class LogInJFrame extends javax.swing.JFrame { /** Creates new form LogInJFrame */ private EntityManager em = LogInPersistence.getEm(); public LogInJFrame() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException ex) { Logger.getLogger(LogInJFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(LogInJFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(LogInJFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedLookAndFeelException ex) { Logger.getLogger(LogInJFrame.class.getName()).log(Level.SEVERE, null, ex); } initComponents(); } /** 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">//GEN-BEGIN:initComponents private void initComponents() { jLabel3 = new javax.swing.JLabel(); jButton3 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); namejTextField = new javax.swing.JTextField(); passwordjPasswordField = new javax.swing.JPasswordField(); logInjButton = new javax.swing.JButton(); quitjButton = new javax.swing.JButton(); jLabel3.setText("jLabel3"); jButton3.setText("jButton3"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("用户姓名"); jLabel2.setText("用户密码"); passwordjPasswordField.setEchoChar('#'); logInjButton.setText("登 录"); logInjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logInjButtonActionPerformed(evt); } }); quitjButton.setText("退 出"); quitjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { quitjButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(logInjButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(quitjButton)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel2) .addGap(18, 18, 18) .addComponent(passwordjPasswordField)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(namejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(28, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(namejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(33, 33, 33) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(passwordjPasswordField, 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(logInjButton) .addComponent(quitjButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void quitjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitjButtonActionPerformed // TODO add your handling code here: int result = JOptionPane.showConfirmDialog(this, "您确实要退出系统?", "提示", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { System.exit(0); } }//GEN-LAST:event_quitjButtonActionPerformed private void logInjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logInjButtonActionPerformed // TODO add your handling code here: boolean flag=true; boolean check; People user = null; String name=namejTextField.getText(); String password=String.copyValueOf(passwordjPasswordField.getPassword()); if(name.equals("")||password.equals("")){ flag =false; JOptionPane.showMessageDialog(this, "用户名或密码不能为空!", "登录失败", JOptionPane.INFORMATION_MESSAGE); }else if(flag=true){ try { user = (People) em.createQuery("select user from People as user where user.name= '" + namejTextField.getText() + "'"+"and user.password='"+password+"'").getSingleResult(); } catch (NoResultException e) { check = false; JOptionPane.showMessageDialog(this, "该用户不存在或者密码输入有误!", "登录失败", JOptionPane.INFORMATION_MESSAGE); return; } if(check=true){ JOptionPane.showMessageDialog(this, "登录系统成功!", "提示", JOptionPane.INFORMATION_MESSAGE); } } }//GEN-LAST:event_logInjButtonActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new LogInJFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JButton logInjButton; private javax.swing.JTextField namejTextField; private javax.swing.JPasswordField passwordjPasswordField; private javax.swing.JButton quitjButton; // End of variables declaration//GEN-END:variables}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -