⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newjpanel.java

📁 ATM机模拟 由于学习ATM机的一些简单操作。
💻 JAVA
字号:
/* * NewJPanel.java * * Created on 2008年12月14日, 下午2:45 */package atm;/** * * @author  刘超 */public class NewJPanel extends javax.swing.JPanel {        /** Creates new form NewJPanel */    public NewJPanel() {        initComponents();        action = 0;    }    public void setAcc(BankAccount theA,ATMView mainView){        theAccount = theA;        view = mainView;    }    /** 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.     */    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents    private void initComponents() {        jButton1 = new javax.swing.JButton();        jButton2 = new javax.swing.JButton();        jButton3 = new javax.swing.JButton();        jButton4 = new javax.swing.JButton();        jLabel1 = new javax.swing.JLabel();        jButton5 = new javax.swing.JButton();        jScrollPane1 = new javax.swing.JScrollPane();        jTextArea1 = new javax.swing.JTextArea();        setName("Form"); // NOI18N        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(atm.ATMApp.class).getContext().getResourceMap(NewJPanel.class);        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N        jButton1.setActionCommand(resourceMap.getString("jButton1.actionCommand")); // NOI18N        jButton1.setName("jButton1"); // NOI18N        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                jButton1MouseClicked(evt);            }        });        jButton1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton1ActionPerformed(evt);            }        });        jButton2.setFont(resourceMap.getFont("jButton2.font")); // NOI18N        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N        jButton2.setName("jButton2"); // NOI18N        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                jButton2MouseClicked(evt);            }        });        jButton2.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton2ActionPerformed(evt);            }        });        jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N        jButton3.setName("jButton3"); // NOI18N        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                jButton3MouseClicked(evt);            }        });        jButton4.setFont(resourceMap.getFont("jButton4.font")); // NOI18N        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N        jButton4.setName("jButton4"); // NOI18N        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                jButton4MouseClicked(evt);            }        });        jButton4.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton4ActionPerformed(evt);            }        });        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N        jLabel1.setName("jLabel1"); // NOI18N        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N        jButton5.setName("jButton5"); // NOI18N        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                jButton5MouseClicked(evt);            }        });        jScrollPane1.setName("jScrollPane1"); // NOI18N        jTextArea1.setColumns(20);        jTextArea1.setRows(5);        jTextArea1.setName("jTextArea1"); // NOI18N        jScrollPane1.setViewportView(jTextArea1);        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);        this.setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addGap(24, 24, 24)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(layout.createSequentialGroup()                        .addGap(110, 110, 110)                        .addComponent(jButton5))                    .addGroup(layout.createSequentialGroup()                        .addGap(34, 34, 34)                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE))))                .addContainerGap(45, javax.swing.GroupLayout.PREFERRED_SIZE))        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addGap(25, 25, 25)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jLabel1))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)                    .addGroup(layout.createSequentialGroup()                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))                    .addComponent(jScrollPane1))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jButton5))                .addContainerGap(41, Short.MAX_VALUE))        );    }// </editor-fold>//GEN-END:initComponents    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed        // TODO add your handling code here:    }//GEN-LAST:event_jButton1ActionPerformed    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed        // TODO add your handling code here:    }//GEN-LAST:event_jButton2ActionPerformed    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed        // TODO add your handling code here:    }//GEN-LAST:event_jButton4ActionPerformed    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked        // TODO add your handling code here:        jLabel1.setText("帐户信息为:");        jTextArea1.setText("用户名:"+theAccount.getINFO()+                "\n余额:"+theAccount.getMoney());    }//GEN-LAST:event_jButton1MouseClicked    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked        // TODO add your handling code here:        jLabel1.setText("输入金额:");        jTextArea1.setText(null);        action = 1;    }//GEN-LAST:event_jButton3MouseClicked    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked        // TODO add your handling code here:        jLabel1.setText("输入金额:");        jTextArea1.setText(null);        action = 2;    }//GEN-LAST:event_jButton2MouseClicked    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked        // TODO add your handling code here:        if(action == 1){            int money = Integer.parseInt(jTextArea1.getText());            theAccount.setMoney(theAccount.getMoney()+money);            jTextArea1.setText("存款成功");            action = 0;        }        else if(action == 2){            int money = Integer.parseInt(jTextArea1.getText());            if(money > theAccount.getMoney())                jTextArea1.setText("你没有足够的金钱");            else{                theAccount.setMoney(theAccount.getMoney()-money);                jTextArea1.setText("取款成功");            }            action = 0;        }        else{            jTextArea1.setText(null);            jLabel1.setText("请选择操作");        }    }//GEN-LAST:event_jButton5MouseClicked    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked        // TODO add your handling code here:        this.setVisible(false);        view.getmian().setVisible(true);        view.setComponent(view.getmian());    }//GEN-LAST:event_jButton4MouseClicked            // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JButton jButton3;    private javax.swing.JButton jButton4;    private javax.swing.JButton jButton5;    private javax.swing.JLabel jLabel1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JTextArea jTextArea1;    // End of variables declaration//GEN-END:variables    private BankAccount theAccount;    private int action;    private ATMView view;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -