📄 bank.java
字号:
/* * Bank.java * * Created on 2004年9月19日, 下午1:55 *//** * * @author litertiger */public class Bank extends javax.swing.JFrame { /** Creates new form Bank */ public Bank() { for(int i=0;i<accounts.length;i++) accounts[i]=100000; start(); initComponents(); } public void transfer(int from,int into,int amount) { if((accounts[from]>=amount)&&(from!=into)) { int newAccountFrom=accounts[from]-amount; int newAmountTo=accounts[into]+amount; wasteSomeTime(); accounts[from]=newAccountFrom; accounts[into]=newAmountTo; } } private void start() { stop(); for(int i=0;i<accounts.length;i++) customer[i]=new Customer(i,this); } private void stop() { for(int i=0;i<accounts.length;i++) if(customer[i]!=null) customer[i].halt(); } private void wasteSomeTime() { try{ Thread.sleep(WASTE_TIME); } catch(InterruptedException e) { } } private void showAccounts() { } /** 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. */ private void initComponents() {//GEN-BEGIN:initComponents jTextArea1 = new javax.swing.JTextArea(); jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); getContentPane().setLayout(null); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jTextArea1.setEditable(false); jTextArea1.setWrapStyleWord(true); getContentPane().add(jTextArea1); jTextArea1.setBounds(20, 30, 430, 250); jLabel1.setText("Transfers complete:"); getContentPane().add(jLabel1); jLabel1.setBounds(20, 0, 340, 30); jButton1.setText("show account"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(10, 300, 110, 25); jButton2.setText("restart"); getContentPane().add(jButton2); jButton2.setBounds(200, 300, 70, 25); jButton3.setText("stop"); getContentPane().add(jButton3); jButton3.setBounds(330, 300, 70, 25); pack(); }//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformedint sum=0;for(int i=0;i<accounts.length;i++){ sum+=accounts[i]; jTextArea1.append("\nAccount"+i+":$"+accounts[i]); // TODO 将在此处增加您的处理代码:}jTextArea1.append("\n total Amount :$"+sum+"\n");jTextArea1.append("\n Total Transfer: $"+counter+"\n"); }//GEN-LAST:event_jButton1ActionPerformed /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm System.exit(0); }//GEN-LAST:event_exitForm /** * @param args the command line arguments */ public static void main(String args[]) { new Bank().show(); } // 变量声明 - 不进行修改//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JTextArea jTextArea1; // 变量声明结束//GEN-END:variables protected final static int NUM_ACCOUNTS=8; protected final static int WASTE_TIME=1; private int accounts[]=new int[NUM_ACCOUNTS]; private Customer customer[]=new Customer[NUM_ACCOUNTS]; private int counter=0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -