| « | November 2025 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 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和内存利用率,设置主机时间.
|
|
|
回复:强大的mustang 原创空间
bean(游客)发表评论于2007/6/21 14:59:16 |
|
» 1 »
|