ptg7068951
Scroll Panes 221
22: JLabel subjectLabel = new JLabel(“Subject:”);
23: row2.add(subjectLabel);
24: JTextField subject = new JTextField(24);
25: row2.add(subject);
26: add(row2);
27:
28: JPanel row3 = new JPanel();
29: JLabel messageLabel = new JLabel(“Message:”);
30: row3.add(messageLabel);
31: JTextArea message = new JTextArea(4, 22);
32: message.setLineWrap(true);
33: message.setWrapStyleWord(true);
34: JScrollPane scroll = new JScrollPane(message,
35: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
36: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
37: row3.add(scroll);
38: add(row3);
39:
40: JPanel row4 = new JPanel();
41: JButton send = new JButton(“Send”);
42: row4.add(send);
43: add(row4);
44:
45: setVisible(true);
46: }
47:
48: private voidsetLookAndFeel() {
49: try {
50: UIManager.setLookAndFeel(
51: “com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”
52: );
53: } catch(Exception exc) {
54: // ignore error
55: }
56: }
57:
58: public static voidmain(String[] arguments) {
59: MailWriter mail = new MailWriter();
60: }
61: }
When you run the application, you should see a window like the one in
Figure 16.1.
The MailWriterapplication is a GUI used to compose an email. There’s no
event-handling code in the program, so you can’t do anything with the
data entered in the form.
LISTING 16.1 Continued