📄 previewemailpanel.java
字号:
package Email.awt.net;
import java.awt.*;
import java.awt.event.*;
import Email.net.*;
import Email.awt.*;
//浏览当前邮件模板
public class PreviewEmailPanel extends OutlinedPanel {
private TextField from;
private TextField to;
private TextField subject;
private TextField attachment;
private TextArea contents;
private Label fromLabel;
private Label toLabel;
private Label subjectLabel;
private Label attachmentLabel;
//当前邮件面板初始化
private void init(int rows, int cols) {
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridBag);
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(1,2,1,2);
c.weightx = 0.0;
gridBag.setConstraints( fromLabel = new Label("From: "), c );
add(fromLabel);
from = new TextField();
from.setEditable(false);
c.weightx = 1.0;
gridBag.setConstraints(from,c);
add(from);
c.gridwidth = GridBagConstraints.RELATIVE;
c.weightx = 0.0;
gridBag.setConstraints(toLabel = new Label("To: "), c);
add(toLabel);
to = new TextField();
to.setEditable(false);
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1.0;
gridBag.setConstraints(to,c);
add(to);
c.gridwidth = 1;
c.weightx = 0.0;
gridBag.setConstraints( subjectLabel = new Label("Subject: "), c );
add( subjectLabel );
subject = new TextField();
subject.setEditable(false);
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1.0;
gridBag.setConstraints(subject,c);
add(subject);
c.gridwidth = 1;
c.weightx = 0.0;
gridBag.setConstraints( attachmentLabel = new Label("Attachment: "), c );
add( attachmentLabel );
attachment = new TextField();
attachment.setEditable(false);
//c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1.0;
gridBag.setConstraints(attachment,c);
add(attachment);
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1.0;
Button saveAs = new Button("Save As.."); //附件另存
saveAs.addActionListener
(
new ActionListener() {
public void actionPerformed( ActionEvent e ){
//在此设置选择对话框
Frame f;
FileDialog fd;
f = new Frame("FileDialog Example");
fd = new FileDialog( f,"FileDialog",FileDialog.SAVE );
fd.setSize(350,150);
fd.setVisible(true);
//attachment.setText( fd.getDirectory() + fd.getFile() );
}
}
);
saveAs.setSize(1,1);
gridBag.setConstraints( saveAs,c );
add( saveAs );
contents = new TextArea(rows,cols);
contents.setEditable(false);
c.gridwidth = GridBagConstraints.REMAINDER;
c.weighty = 1.0;
gridBag.setConstraints(contents,c);
add(contents);
}
public void addNotify() {
super.addNotify();
Font f = fromLabel.getFont();
fromLabel.setFont( new Font( fromLabel.getName(),Font.BOLD,f.getSize() ) );
f = toLabel.getFont();
toLabel.setFont( new Font( toLabel.getName(),Font.BOLD,f.getSize() ) );
f = subjectLabel.getFont();
subjectLabel.setFont( new Font( subjectLabel.getName(),Font.BOLD,f.getSize() ) );
f = attachmentLabel.getFont();
attachmentLabel.setFont( new Font( attachmentLabel.getName(),Font.BOLD,f.getSize() ) );
}
//显示当前邮件信息
public void preview(Email email) {
//设置邮件发邮件地址,接收地址和内容
if (email == null)
email = new Email();
from.setText( email.getFrom() );
to.setText( email.getToAsString() );
subject.setText( email.getSubject() );
contents.setText( email.getBodyAsString() );
}
public PreviewEmailPanel(int rows, int cols) {
super("Preview");
init(rows,cols);
}
public PreviewEmailPanel(int rows, int cols, Email email) {
super("Preview");
init(rows,cols);
preview(email);
}
/*
public static void main(String[] args) {
WinFrame f = new WinFrame
(
"PreviewEmailPanel Demo",new PreviewEmailPanel
(4,50,
new Email
(
"From: wy82@21cn.com \n" +
"To: psw82@126.com\n" +
"Subject: Hello!"
)
)
).appMainWindow();
f.pack();
f.setVisible(true);
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -