本站首页    管理页面    写新日志    退出


«November 2025»
1
2345678
9101112131415
16171819202122
23242526272829
30


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:邢红瑞的blog
日志总数:523
评论数量:1142
留言数量:0
访问次数:9731615
建立时间:2004年12月20日




[java语言]强大的mustang 
原创空间

邢红瑞 发表于 2006/11/6 16:44:18

 jdk6确实很强大,以前要实现系统托盘的功能,要使用systray4j,还得用jni.这次mustang自带了import java.awt.AWTException;import java.awt.Image;import java.awt.MenuItem;import java.awt.PopupMenu;import java.awt.SystemTray;import java.awt.Toolkit;import java.awt.TrayIcon;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;/** * * @author hongrui xing */public class Systray {  /**  * @param args  */ public static void main(String[] args) {  Image image = Toolkit.getDefaultToolkit().getImage("images/javacup.gif");      TrayIcon trayIcon = null;      if (SystemTray.isSupported()) {          // get the SystemTray instance          SystemTray tray = SystemTray.getSystemTray();                    // create a action listener to listen for default action executed on the tray icon          ActionListener listener = new ActionListener() {              public void actionPerformed(ActionEvent e) {                                }          };          // create a popup menu          PopupMenu popup = new PopupMenu();          // create menu item for the default action          MenuItem defaultItem = new MenuItem("test entry");          defaultItem.addActionListener(listener);          popup.add(defaultItem);          /// ... add other items          // construct a TrayIcon          trayIcon = new TrayIcon(image, "Tray Demo", popup);          trayIcon.setImageAutoSize(true);          // set the TrayIcon properties          trayIcon.addActionListener(listener);          // ...          // add the tray image          try {    tray.add(trayIcon);   } catch (AWTException e1) {    // TODO Auto-generated catch block    e1.printStackTrace();   }          // ...      } else {          // disable tray option in your application or          // perform other actions      }      // ...      // some time later      // the application state has changed - update the image      if (trayIcon != null) {       trayIcon.setImage(image);      }      // ... } }而且还可以查看硬盘空间  File f = new File("e:/");// prints the volume size in bytes.        System.out.println(f.getTotalSpace());// prints the total free bytes for the volume in bytes.        System.out.println(f.getFreeSpace());// prints an accurate estimate of the total free (and available) bytes// on the volume. This method may return the same result as 'getFreeSpace()' on// some platforms.        System.out.println(f.getUsableSpace());目前还没有的功能,查看cpu和内存利用率,设置主机时间.  


阅读全文(4913) | 回复(1) | 编辑 | 精华
 


回复:强大的mustang
原创空间

bean(游客)发表评论于2007/6/21 14:59:16

Jdk哪天能查看cpu温度了,就好咯。


个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


» 1 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 4.656 second(s), page refreshed 144812346 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号