Main.java
上传用户:xinkaifrp
上传日期:2021-05-08
资源大小:372k
文件大小:9k
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * Main.java
- *
- * Created on 2009-6-25, 9:54:58
- */
- package com.financing;
- import com.financing.dao.LoginDao;
- import com.financing.dao.UserMoneyDao;
- import java.awt.Dimension;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import javax.swing.UIManager;
- /**
- *
- * @author Administrator
- */
- public class Main extends javax.swing.JFrame {
- /** Creates new form Main */
- public Main() {
- initComponents();
- this.setTitle("个人理财系统登录");
- }
- /** 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() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jPasswordField1 = new javax.swing.JPasswordField();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("个人理财登录");
- jLabel2.setText("用户名");
- jLabel3.setText("密码");
- jTextField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1ActionPerformed(evt);
- }
- });
- jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jPasswordField1ActionPerformed(evt);
- }
- });
- jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyPressed(java.awt.event.KeyEvent evt) {
- jPasswordField1KeyPressed(evt);
- }
- });
- jButton1.setText("登录");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("注册");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(200, 200, 200)
- .addComponent(jLabel1)
- .addContainerGap(192, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addGap(141, 141, 141)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 99, Short.MAX_VALUE)
- .addComponent(jButton2))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGap(12, 12, 12)))
- .addGap(47, 47, 47)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPasswordField1, 0, 0, Short.MAX_VALUE)
- .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))))
- .addGap(110, 110, 110))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(27, 27, 27)
- .addComponent(jLabel1)
- .addGap(30, 30, 30)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(jTextField1, 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(jLabel3)
- .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(66, 66, 66)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap(41, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
- // TODO add your handling code here:
- }//GEN-LAST:event_jTextField1ActionPerformed
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- LoginDao dao = new LoginDao();
- String username = jTextField1.getText();
- if (!username.equals("") && !new String(jPasswordField1.getPassword()).equals("")) {
- if (dao.login(username, new String(jPasswordField1.getPassword()))) {
- this.dispose();
- UserMoneyDao moneyDao = new UserMoneyDao();
- Double money = null;
- try {
- money = moneyDao.getUserMoney(username);
- if (money !=null) {//余额不为null
- Financing financing = new Financing();
- financing.setUserName(username);
- financing.setComboType();
- financing.setTextMoney(money);//设置用户和金额
- financing.setVisible(true);
- }else{
- JOptionPane.showConfirmDialog(rootPane, "读取数据错误");
- }
- } catch (Exception ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else {
- JOptionPane.showMessageDialog(rootPane, "用户名或密码有误");
- }
- } else {
- JOptionPane.showMessageDialog(rootPane, "请输入用户名和密码");
- }
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed
- // TODO add your handling code here:
- }//GEN-LAST:event_jPasswordField1ActionPerformed
- private void jPasswordField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordField1KeyPressed
- if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
- jButton1ActionPerformed(null);
- }
- }//GEN-LAST:event_jPasswordField1KeyPressed
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- AddUser addUser=new AddUser();
- addUser.setVisible(true);
- }//GEN-LAST:event_jButton2ActionPerformed
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- Main m = new Main();
- m.pack();
- Dimension d=m.getToolkit().getScreenSize();
- Dimension d1= m.getSize();
- m.setLocation((d.width-d1.width)/2,(d.height-d1.height)/2);
- m.setResizable(false);
- m.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JPasswordField jPasswordField1;
- private javax.swing.JTextField jTextField1;
- // End of variables declaration//GEN-END:variables
- }