Main.java
上传用户:xinkaifrp
上传日期:2021-05-08
资源大小:372k
文件大小:9k
源码类别:

家庭/个人应用

开发平台:

Java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. /*
  6.  * Main.java
  7.  *
  8.  * Created on 2009-6-25, 9:54:58
  9.  */
  10. package com.financing;
  11. import com.financing.dao.LoginDao;
  12. import com.financing.dao.UserMoneyDao;
  13. import java.awt.Dimension;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16. import javax.swing.JOptionPane;
  17. import javax.swing.UIManager;
  18. /**
  19.  *
  20.  * @author Administrator
  21.  */
  22. public class Main extends javax.swing.JFrame {
  23.     /** Creates new form Main */
  24.     public Main() {
  25.         initComponents();
  26.         this.setTitle("个人理财系统登录");
  27.     }
  28.     /** This method is called from within the constructor to
  29.      * initialize the form.
  30.      * WARNING: Do NOT modify this code. The content of this method is
  31.      * always regenerated by the Form Editor.
  32.      */
  33.     @SuppressWarnings("unchecked")
  34.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  35.     private void initComponents() {
  36.         jLabel1 = new javax.swing.JLabel();
  37.         jLabel2 = new javax.swing.JLabel();
  38.         jLabel3 = new javax.swing.JLabel();
  39.         jTextField1 = new javax.swing.JTextField();
  40.         jPasswordField1 = new javax.swing.JPasswordField();
  41.         jButton1 = new javax.swing.JButton();
  42.         jButton2 = new javax.swing.JButton();
  43.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  44.         jLabel1.setText("个人理财登录");
  45.         jLabel2.setText("用户名");
  46.         jLabel3.setText("密码");
  47.         jTextField1.addActionListener(new java.awt.event.ActionListener() {
  48.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  49.                 jTextField1ActionPerformed(evt);
  50.             }
  51.         });
  52.         jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
  53.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  54.                 jPasswordField1ActionPerformed(evt);
  55.             }
  56.         });
  57.         jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
  58.             public void keyPressed(java.awt.event.KeyEvent evt) {
  59.                 jPasswordField1KeyPressed(evt);
  60.             }
  61.         });
  62.         jButton1.setText("登录");
  63.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  64.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  65.                 jButton1ActionPerformed(evt);
  66.             }
  67.         });
  68.         jButton2.setText("注册");
  69.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  70.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  71.                 jButton2ActionPerformed(evt);
  72.             }
  73.         });
  74.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  75.         getContentPane().setLayout(layout);
  76.         layout.setHorizontalGroup(
  77.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  78.             .addGroup(layout.createSequentialGroup()
  79.                 .addGap(200, 200, 200)
  80.                 .addComponent(jLabel1)
  81.                 .addContainerGap(192, Short.MAX_VALUE))
  82.             .addGroup(layout.createSequentialGroup()
  83.                 .addGap(141, 141, 141)
  84.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  85.                     .addGroup(layout.createSequentialGroup()
  86.                         .addComponent(jButton1)
  87.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 99, Short.MAX_VALUE)
  88.                         .addComponent(jButton2))
  89.                     .addGroup(layout.createSequentialGroup()
  90.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  91.                             .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  92.                             .addGroup(layout.createSequentialGroup()
  93.                                 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  94.                                 .addGap(12, 12, 12)))
  95.                         .addGap(47, 47, 47)
  96.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  97.                             .addComponent(jPasswordField1, 0, 0, Short.MAX_VALUE)
  98.                             .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))))
  99.                 .addGap(110, 110, 110))
  100.         );
  101.         layout.setVerticalGroup(
  102.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103.             .addGroup(layout.createSequentialGroup()
  104.                 .addGap(27, 27, 27)
  105.                 .addComponent(jLabel1)
  106.                 .addGap(30, 30, 30)
  107.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  108.                     .addComponent(jLabel2)
  109.                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  110.                 .addGap(18, 18, 18)
  111.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  112.                     .addComponent(jLabel3)
  113.                     .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  114.                 .addGap(66, 66, 66)
  115.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  116.                     .addComponent(jButton1)
  117.                     .addComponent(jButton2))
  118.                 .addContainerGap(41, Short.MAX_VALUE))
  119.         );
  120.         pack();
  121.     }// </editor-fold>//GEN-END:initComponents
  122.     private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
  123.         // TODO add your handling code here:
  124.     }//GEN-LAST:event_jTextField1ActionPerformed
  125.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  126.         LoginDao dao = new LoginDao();
  127.         String username = jTextField1.getText();
  128.         if (!username.equals("") && !new String(jPasswordField1.getPassword()).equals("")) {
  129.             if (dao.login(username, new String(jPasswordField1.getPassword()))) {
  130.                 this.dispose();
  131.                 UserMoneyDao moneyDao = new UserMoneyDao();
  132.                 Double money = null;
  133.                 try {
  134.                     money = moneyDao.getUserMoney(username);
  135.                     if (money !=null) {//余额不为null
  136.                         Financing financing = new Financing();
  137.                         financing.setUserName(username);
  138.                         financing.setComboType();
  139.                         financing.setTextMoney(money);//设置用户和金额
  140.                         financing.setVisible(true);
  141.                     }else{
  142.                         JOptionPane.showConfirmDialog(rootPane, "读取数据错误");
  143.                     }
  144.                 } catch (Exception ex) {
  145.                     Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  146.                 }
  147.             } else {
  148.                 JOptionPane.showMessageDialog(rootPane, "用户名或密码有误");
  149.             }
  150.         } else {
  151.             JOptionPane.showMessageDialog(rootPane, "请输入用户名和密码");
  152.         }
  153.     }//GEN-LAST:event_jButton1ActionPerformed
  154.     private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed
  155.         // TODO add your handling code here:
  156.     }//GEN-LAST:event_jPasswordField1ActionPerformed
  157.     private void jPasswordField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordField1KeyPressed
  158.         if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
  159.             jButton1ActionPerformed(null);
  160.         }
  161.     }//GEN-LAST:event_jPasswordField1KeyPressed
  162.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  163.        AddUser addUser=new AddUser();
  164.        addUser.setVisible(true);
  165.     }//GEN-LAST:event_jButton2ActionPerformed
  166.     /**
  167.      * @param args the command line arguments
  168.      */
  169.     public static void main(String args[]) {
  170.         java.awt.EventQueue.invokeLater(new Runnable() {
  171.             public void run() {
  172.                 try {
  173.                     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  174.                 } catch (Exception ex) {
  175.                     ex.printStackTrace();
  176.                 }
  177.                 Main m = new Main();
  178.                 m.pack();
  179.                 Dimension d=m.getToolkit().getScreenSize();
  180.                 Dimension d1= m.getSize();
  181.                 m.setLocation((d.width-d1.width)/2,(d.height-d1.height)/2);
  182.                 m.setResizable(false);
  183.                 m.setVisible(true);
  184.             }
  185.         });
  186.     }
  187.     // Variables declaration - do not modify//GEN-BEGIN:variables
  188.     private javax.swing.JButton jButton1;
  189.     private javax.swing.JButton jButton2;
  190.     private javax.swing.JLabel jLabel1;
  191.     private javax.swing.JLabel jLabel2;
  192.     private javax.swing.JLabel jLabel3;
  193.     private javax.swing.JPasswordField jPasswordField1;
  194.     private javax.swing.JTextField jTextField1;
  195.     // End of variables declaration//GEN-END:variables
  196. }