項目結構:html
運行效果:java
若是你感興趣,請不要那個人郵箱作測試!!!!服務器
==========================================================app
下面是代碼部分socket
==========================================================ide
/SendMail/src/com/b510/sendmail/main/SendMailMain.java佈局
1 package com.b510.sendmail.main; 2 3 import com.b510.sendmail.ui.SendMailUI; 4 5 /** 6 * @author Hongten 7 * 8 * @time 2012-4-4 2012 9 */ 10 public class SendMailMain { 11 public static void main(String[] args) { 12 SendMailUI sendMailUI = new SendMailUI("send E-Mail"); 13 } 14 }
/SendMail/src/com/b510/sendmail/ui/MyTray.java測試
1 package com.b510.sendmail.ui; 2 3 import java.awt.AWTException; 4 import java.awt.Image; 5 import java.awt.MenuItem; 6 import java.awt.PopupMenu; 7 import java.awt.SystemTray; 8 import java.awt.TrayIcon; 9 import java.awt.event.ActionEvent; 10 import java.awt.event.ActionListener; 11 import java.awt.event.MouseEvent; 12 import java.awt.event.MouseListener; 13 14 import javax.swing.ImageIcon; 15 import javax.swing.JFrame; 16 17 public class MyTray implements ActionListener, MouseListener { 18 private Image icon;// 圖標 19 private TrayIcon trayIcon; 20 private SystemTray systemTray;// 系統托盤 21 22 private SendMailUI sendMailUI; // 托盤所屬主窗體 23 private PopupMenu pop = new PopupMenu(); // 彈出菜單 24 // 菜單選項 25 /** 還原 */ 26 private MenuItem open = new MenuItem("Restore"); 27 /** 退出*/ 28 private MenuItem exit =new MenuItem("Exit"); 29 public MyTray(SendMailUI sendMailUI) { 30 this.sendMailUI = sendMailUI; 31 // 獲得托盤的圖標 32 icon = new ImageIcon(this.getClass().getClassLoader().getResource( 33 "resources/mytray.png")).getImage(); 34 35 if (SystemTray.isSupported()) { 36 systemTray = SystemTray.getSystemTray(); 37 // 設置鼠標通過圖標時,顯示的內容 38 trayIcon = new TrayIcon(icon, "YouSiNi", pop); 39 pop.add(open); 40 pop.add(exit); 41 // 添加系統托盤 42 try { 43 systemTray.add(trayIcon); 44 } catch (AWTException e1) { 45 e1.printStackTrace(); 46 trayIcon.addMouseListener(this); 47 } 48 } 49 trayIcon.addMouseListener(this); 50 exit.addActionListener(this); 51 open.addActionListener(this); 52 } 53 54 @Override 55 public void actionPerformed(ActionEvent e) { 56 if(e.getSource()==exit){ 57 //退出系統 58 System.exit(0); 59 }else if (e.getSource() == open) { 60 // 單點擊菜單中的"還原"選項時,還原窗口 61 sendMailUI.iconed = false; 62 friendListSet(true); 63 } 64 } 65 66 @Override 67 public void mouseClicked(MouseEvent e) { 68 // 但鼠標點擊一次的時候,進行彈出窗口 69 if (e.getClickCount() == 1 && e.getButton() != MouseEvent.BUTTON3) { 70 if (!sendMailUI.isVisible()) { 71 friendListSet(true); 72 } else { 73 friendListSet(false); 74 } 75 } 76 // 但鼠標點擊兩次的時候,進行彈出窗口 77 // 若是窗口有顯示,則隱藏窗口,不然顯示窗口 78 if (e.getClickCount() == 2 && e.getButton() != MouseEvent.BUTTON3) { 79 if (!sendMailUI.isVisible()) { 80 friendListSet(true); 81 } else { 82 friendListSet(false); 83 } 84 } 85 } 86 87 /** 88 * 設置friendList的可見性 89 */ 90 private void friendListSet(boolean