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。