public static void createPopupMenu(){ pm = new PopupMenu(); MenuItem openBrowser = new MenuItem("Open My Blog"); openBrowser.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openBrowser("http://blog.csdn.net/chinajash"); } });
MenuItem sendMail = new MenuItem("Send Mail to me"); sendMail.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sendMail("mailto:chinajash@yahoo.com.cn"); } });
MenuItem edit = new MenuItem("Edit Text File"); sendMail.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { edit(); } });
MenuItem exitMenu = new MenuItem("&Exit"); exitMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); pm.add(openBrowser); pm.add(sendMail); pm.add(edit); pm.addSeparator(); pm.add(exitMenu); } } 假如在Windows中運行該程序,可以看到在系統托盤區有一個圖標,右擊該圖標會彈出一個菜單,點擊Open My Blog會打開IE,并瀏覽我設定的BLOG地址;點擊Send Mail to me會打開Outlook EXPress給我發郵件;點擊Edit Text File會打開記事本編輯在程序中創建的文件test.txt。