?? receiveview.java
字號:
package org.hwmhere.email.view;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Collection;
import org.hwmhere.util.swing.Console;
import org.hwmhere.email.client.*;
import org.hwmhere.email.impl.Email;
import org.hwmhere.email.impl.util.EmailUtil;
import org.hwmhere.email.mailet.MailAddress;
public class ReceiveView extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTextField addressField = new JTextField(50);
private JTextField passwordField = new JTextField(50);
private JLabel addressLable = new JLabel("Your mail address:");
private JLabel passwordLable = new JLabel("Your mail password:");
private JButton getButton = new JButton("Get Emails");
private DefaultListModel lItems = new DefaultListModel();
private JList lst = new JList(lItems);
private ArrayList emailList = new ArrayList();
private MailAddress user;
String receivePath = "D:/test/receive/";
public ReceiveView() {
this.setTitle("EmailBetterByRUDP_By_1040310515_HWM");
giveLayout();
giveAction();
try {
receivePath = "D:/test/receive/";
user = new MailAddress("hwmhere@localhost");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void giveLayout() {
Container cp = this.getContentPane();
cp.setLayout(null);
cp.add(addressLable);
cp.add(passwordLable);
cp.add(addressField);
cp.add(passwordField);
cp.add(getButton);
cp.add(lst);
// x,y,width,hight
addressLable.setBounds(0, 4, 200, 30);
passwordLable.setBounds(0, 40, 200, 30);
addressField.setBounds(220, 4, 200, 30);
passwordField.setBounds(220, 40, 200, 30);
getButton.setBounds(150, 100, 100, 30);
lst.setBounds(20, 200, 800, 500);
}
private void giveAction() {
getButton.addActionListener(bl);
lst.addListSelectionListener(ll);
}
private ActionListener bl = new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
user = new MailAddress(addressField.getText());
String userPath = receivePath + user.toString() + "/";
FilenameFilter mailFileFilter = new FilenameFilter() {
public boolean accept(File file, String name) {
if (name.endsWith(".email")) {
return true;
} else {
return false;
}
}
};
File mailsDir = new File(userPath);
// 先將list清空
lItems.clear();
emailList.clear();
File[] files = mailsDir.listFiles(mailFileFilter);
for (int x = 0; x < files.length; x++) {
File aFile = files[x];
String filename = userPath + aFile.getName();
// 添加到列表當(dāng)中
Email tempMail = EmailUtil.getEmail(filename);
emailList.add(tempMail);
lItems.addElement("Title"+
tempMail.getAttribute("title")+" \tFrom:"+tempMail.getSender()+" Date:"+
tempMail.getLastUpdated()
);
}
} catch (Exception e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, "Error", "Hey!",
JOptionPane.ERROR_MESSAGE);
}
}
};
private ListSelectionListener ll = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
int index = lst.getMinSelectionIndex();
Email tempEmail = (Email)emailList.get(index);
String message = new String(tempEmail.getMessage());
String info = "Titile : "+tempEmail.getAttribute("title") +"\nDate : "+tempEmail.getLastUpdated() + "\n" +
"--------------------------------------------------------------------------------\n";
String title = "From :" + tempEmail.getSender().toString() + " At :" + tempEmail.getLastUpdated();
JOptionPane.showMessageDialog(null,info + message,title,
JOptionPane.INFORMATION_MESSAGE);
// TODO:
}
};
public static void main(String[] args) {
Console.run(new ReceiveView(), 1000, 750);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -