📄 mmgui.java
字号:
// GUI 斉儊乕儖僋儔僀傾儞僩僾儘僌儔儉MMGui.java
// 偙偺僾儘僌儔儉偼,僌儔僼傿僇儖側儐乕僓僀儞僞僼僃乕僗傪旛偊偨
// 儊乕儖僋儔僀傾儞僩僾儘僌儔儉偱偡
// 巊偄曽java MMGui
// MMGui.java偺僐儞僷僀儖偵偼,MailManager.java僼傽僀儖偑昁梫偱偡
// 儔僀僽儔儕偺棙梡
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
// MMGui僋儔僗
public class MMGui {
static boolean debug = MailManager.debug;
MailManager mm;
// 柍柤僋儔僗偵傛傞儊乕儖昞帵張棟偺愝掕
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 ("quit".equalsIgnoreCase(cmd)){
System.exit(0);
}else if ("get".equalsIgnoreCase(cmd)){
mm.getmail();
list();
}else if ("send".equalsIgnoreCase(cmd)){
sendMail();
}
}
};
TextArea message;
List list;
Frame f;
// 僐儞僗僩儔僋僞
// 僂傿儞僪僂側偳傪愝掕偟傑偡
public MMGui ()
{
f = new Frame();
f.setSize(600, 480);
GridBagLayout layout = new GridBagLayout();
f.setLayout(layout);
Panel p = new Panel();
// Get儃僞儞
Button b = new Button("Get");
b.addActionListener(buttonAction);
p.add(b);
// Send儃僞儞
b = new Button("Send");
b.addActionListener(buttonAction);
p.add(b);
// Quit儃僞儞
b = new Button("Quit");
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(5);
list.addActionListener(listAction);
layout.setConstraints(list, c);
f.add(list);
// 儊僢僙乕僕僄儕傾偺昞帵
message = new TextArea(18, 70);
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();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -