///////////////////////////////////////////////////////////////////////////////////// // MMGui.java import java.awt.* ; import java.awt.event.* ; import java.util.StringTokenizer ; public class MMGui { static boolean debug = MailManager.debug ; MailManager mm = null ; /** * 無名クラスによるボタン処理の設定 */ ActionListener listAction = new ActionListener() { public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand() ; if(debug) System.out.println("MMGui.listAction: " + cmd) ; StringTokenizer st = new StringTokenizer(cmd) ; readMail(Integer.parseInt(st.nextToken())) ; } }; /** * 無名クラスによるボタン処理の設定 */ ActionListener buttonAction = new ActionListener() { public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand() ; if(debug) System.out.println("MMGui.buttonAction: " + cmd) ; if("終 了".equalsIgnoreCase(cmd)) System.exit(0) ; else if ("受 信".equalsIgnoreCase(cmd)){ mm.getmail() ; list() ; } else if("送 信".equalsIgnoreCase(cmd)) sendMail() ; } }; TextArea message ; List list ; Frame f ; /** * コンストラクタ ウインドウなどの設定 */ public MMGui() { f = new Frame() ; f.setSize(800, 600) ; GridBagLayout layout = new GridBagLayout() ; f.setLayout(layout) ; Panel p = new Panel() ; // Get Button Button b = new Button("受 信") ; b.addActionListener(buttonAction) ; p.add(b) ; // send Button b = new Button("送 信") ; b.addActionListener(buttonAction) ; p.add(b) ; // quit button b = new Button("終 了") ; b.addActionListener(buttonAction) ; p.add(b) ; GridBagConstraints c = new GridBagConstraints() ; c.fill = GridBagConstraints.BOTH ; c.gridwidth = GridBagConstraints.REMAINDER ; layout.setConstraints(p, c) ; f.add(p) ; // メールリストエリアの表示 list = new List(10) ; list.addActionListener(listAction) ; layout.setConstraints(list, c) ; f.add(list) ; // メッセージエリアの表示 message = new TextArea(25, 100) ; message.setEditable(false) ; layout.setConstraints(message, c) ; f.add(message) ; f.show() ; mm = new MailManager() ; list() ; } /** * List メソッド メールのリストを表示します */ void list() { String[] mailList = mm.list() ; list.removeAll() ; for(int i = 0 ; i < mailList.length ; i++) list.add(mailList[i]) ; } /** * readMailメソッド メッセージを表示 */ void readMail(int i) { message.setText(mm.readMail(i)) ; } /** * sendMailメソッド Editorクラスを使ってメールを送信 */ void sendMail(){ new Editor() ; } /** * main メソッド */ public static void main(String[] arg) { new MMGui() ; } /** * Editor クラス メッセージを編集画面を提示し、メールとして送信します。 */ class Editor { Frame f ; TextField subject ; TextField to ; TextArea message ; /** * ボタン処理 */ ActionListener editorAction = new ActionListener() { public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand() ; if(debug) System.out.println("MMGui.Editor.editorAction" + cmd) ; if("OK".equalsIgnoreCase(cmd) ) { mm.sendmail(to.getText(), subject.getText(), message.getText()) ; } f.dispose() ; } } ; /** * コンストラクタ メッセージウインドウを準備 */ Editor() { f = new Frame() ; f.setSize(600, 400) ; subject = new TextField(50) ; to = new TextField(50) ; message = new TextArea(15, 70) ; f.setLayout(new FlowLayout()) ; Panel p = new Panel() ; p.add(new Label("Subject: ")) ; p.add(subject) ; f.add(p) ; p = new Panel() ; p.add(new Label("To:")); p.add(to) ; f.add(p) ; f.add(message) ; Button b = new Button("OK") ; b.addActionListener(editorAction) ; f.add(b) ; b = new Button("CANCEL") ; b.addActionListener(editorAction) ; f.add(b) ; f.show() ; } } }