Java Reference
In-Depth Information
createPanel();
setSize(FRAME_WIDTH, FRAME_HEIGHT);
}
private void createButton()
{
ActionListener listener = new
AddInterestListener();
button.addActionListener(listener);
button = new JButton(ÐAdd InterestÑ);
}
private void createPanel()
{
panel = new JPanel();
panel.add(button);
panel.add(label);
add(panel);
}
private JButton button;
private JLabel label;
private JPanel panel;
private BankAccount account;
}
478
479
This approach differs from the programs in Chapter 9 . In those programs, we simply
configured the frame in the main method of a viewer class.
It is a bit more work to provide a separate class for the frame. However, the frame
class makes it easier to organize the code that constructs the user-interface elements.
We will use this approach for all examples in this chapter.
Of course, we still need a class with a main method:
public class InvestmentViewer2
{
public static void main(String[] args)
{
JFrame frame = new InvestmentFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Search WWH ::




Custom Search