MailClient - MailClient.java import import import import...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
MailClient.java import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; /** * A simple mail client with a GUI for sending mail. */ public class MailClient extends Frame { /* The stuff for the GUI. */ private Button btSend = new Button("Send"); private Button btClear = new Button("Clear"); private Button btQuit = new Button("Quit"); private Label fromLabel = new Label("From:"); private TextField fromField = new TextField("", 40); private Label toLabel = new Label("To:"); private TextField toField = new TextField("", 40); private Label subjectLabel = new Label("Subject:"); private TextField subjectField = new TextField("", 40); private Label messageLabel = new Label("Message:"); private TextArea messageText = new TextArea(10, 40); /** * Create a new MailClient window with fields for entering all * the relevant information (From, To, Subject, and message). */ public MailClient() { super("Java Mailclient"); /* Create panels for holding the fields. To make it look nice, create an extra panel for holding all the child panels. */ Panel fromPanel = new Panel(new BorderLayout()); Panel toPanel = new Panel(new BorderLayout()); Panel subjectPanel = new Panel(new BorderLayout()); Panel messagePanel = new Panel(new BorderLayout()); fromPanel.add(fromLabel, BorderLayout.WEST);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
fromPanel.add(fromField, BorderLayout.CENTER); toPanel.add(toLabel, BorderLayout.WEST); toPanel.add(toField, BorderLayout.CENTER); subjectPanel.add(subjectLabel, BorderLayout.WEST); subjectPanel.add(subjectField, BorderLayout.CENTER); messagePanel.add(messageLabel, BorderLayout.NORTH); messagePanel.add(messageText, BorderLayout.CENTER); Panel fieldPanel = new Panel(new GridLayout(0, 1)); fieldPanel.add(fromPanel); fieldPanel.add(toPanel); fieldPanel.add(subjectPanel); /* Create a panel for the buttons and add listeners to the buttons. */ Panel buttonPanel = new Panel(new GridLayout(1, 0)); btSend.addActionListener(new SendListener()); btClear.addActionListener(new ClearListener()); btQuit.addActionListener(new QuitListener()); buttonPanel.add(btSend); buttonPanel.add(btClear); buttonPanel.add(btQuit); /* Add, pack, and show. */ add(fieldPanel, BorderLayout.NORTH); add(messagePanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); pack(); show(); } static public void main(String argv[]) { new MailClient(); } /* Handler for the Send-button. */ class SendListener implements ActionListener { public void actionPerformed(ActionEvent event) { System.out.println("Sending mail");
Background image of page 2
/* First, check that we have the sender and recipient. */ if((fromField.getText()).equals("")) {
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/11/2011 for the course EE 5413 taught by Professor Hingcheungso during the Spring '10 term at City University of Hong Kong.

Page1 / 11

MailClient - MailClient.java import import import import...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online