1 package org.prevayler.demos.demo2.gui; 2 3 import java.awt.Container ; 4 5 import javax.swing.Box ; 6 import javax.swing.JButton ; 7 import javax.swing.JPanel ; 8 import javax.swing.JTextField ; 9 10 import org.prevayler.Prevayler; 11 import org.prevayler.demos.demo2.business.Account; 12 import org.prevayler.demos.demo2.business.transactions.Transfer; 13 14 class TransferFrame extends AccountFrame { 15 16 private final Account account; 17 private JTextField sourceField; 18 private JTextField destinationField; 19 private JTextField amountField; 20 21 TransferFrame(Account account, Prevayler prevayler, Container container) { 22 super("Transfer", prevayler, container); 23 24 this.account = account; 25 sourceField.setText(account.numberString()); 26 27 setBounds(50,50,200,194); 28 } 29 30 protected void addFields(Box fieldBox) { 31 fieldBox.add(labelContainer("From Account")); 32 sourceField = new JTextField (); 33 sourceField.setEnabled(false); 34 fieldBox.add(sourceField); 35 36 fieldBox.add(gap()); 37 fieldBox.add(labelContainer("To Account")); 38 destinationField = new JTextField (); 39 fieldBox.add(destinationField); 40 41 fieldBox.add(gap()); 42 fieldBox.add(labelContainer("Amount")); 43 amountField = new JTextField (); 44 fieldBox.add(amountField); 45 } 46 47 protected void addButtons(JPanel buttonPanel) { 48 buttonPanel.add(new JButton (new OKAction())); 49 } 50 51 private class OKAction extends RobustAction { 52 53 OKAction() { 54 super("OK"); 55 } 56 57 public void action() throws Exception { 58 long destinationNumber = parse(destinationField.getText()); 59 long amount = parse(amountField.getText()); 60 _prevayler.execute(new Transfer(account.number(), destinationNumber, amount)); 61 dispose(); 62 } 63 } 64 } 65 | Popular Tags |