KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > demos > demo2 > gui > TransferFrame


1 package org.prevayler.demos.demo2.gui;
2
3 import java.awt.Container JavaDoc;
4
5 import javax.swing.Box JavaDoc;
6 import javax.swing.JButton JavaDoc;
7 import javax.swing.JPanel JavaDoc;
8 import javax.swing.JTextField JavaDoc;
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 JavaDoc sourceField;
18     private JTextField JavaDoc destinationField;
19     private JTextField JavaDoc amountField;
20     
21     TransferFrame(Account account, Prevayler prevayler, Container JavaDoc 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 JavaDoc fieldBox) {
31         fieldBox.add(labelContainer("From Account"));
32         sourceField = new JTextField JavaDoc();
33         sourceField.setEnabled(false);
34         fieldBox.add(sourceField);
35         
36         fieldBox.add(gap());
37         fieldBox.add(labelContainer("To Account"));
38         destinationField = new JTextField JavaDoc();
39         fieldBox.add(destinationField);
40
41         fieldBox.add(gap());
42         fieldBox.add(labelContainer("Amount"));
43         amountField = new JTextField JavaDoc();
44         fieldBox.add(amountField);
45     }
46
47     protected void addButtons(JPanel JavaDoc buttonPanel) {
48         buttonPanel.add(new JButton JavaDoc(new OKAction()));
49     }
50     
51     private class OKAction extends RobustAction {
52         
53         OKAction() {
54             super("OK");
55         }
56
57         public void action() throws Exception JavaDoc {
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