Java Reference
In-Depth Information
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class AccountWindow extends JFrame {
private JTextField funds, add;
private JButton addButton;
public AccountWindow() {
this.setSize(400, 120);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
funds = new JTextField(30);
add = new JTextField(30);
addButton = new JButton("Add funds");
funds.setEditable(false);
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// Add funds here
}
});
this.add(funds);
this.add(add);
this.add(addButton);
}
}
The interface is Spartan‐looking for now, but it will do, as shown in Figure 12-6.
figure 12-6  
A bigger question on your mind is how to fill in the “Add Funds” box. You want to keep your model
and view as separate as possible, and thus avoid passing an Account object to this view. This is
where the controller comes in. You start out by defining your controller:
import javax.swing.JFrame;
public class AccountController {
Search WWH ::




Custom Search