Teaching how to use the System Tray in Java! - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Java Programming (https://www.supportforums.net/forumdisplay.php?fid=22) +---- Thread: Teaching how to use the System Tray in Java! (/showthread.php?tid=2662) |
Teaching how to use the System Tray in Java! - Project Evolution - 11-07-2009 Learning how to use this exciting API is quite easy. So first lets start. To make this work, we need to import a couple packages, Code: import java.awt.AWTException; We need to figure out if the OS supports the System tray feature in Java, to do so, we add this if-statement, Code: if (SystemTray.isSupported()) { Next up, we are going to implement the SystemTray class as a constructor. Its as shown, Code: SystemTray tray = SystemTray.getSystemTray(); Now we can get started on working on the actual function. Here, we get the image we want as our icon, Code: Image image = Toolkit.getDefaultToolkit().getImage("image.gif"); Fnally we add the second last part, adding the actual icon to the tray. Code: TrayIcon trayIcon = new TrayIcon(image, "Your application is now running..."); And we must add it enclosed in a try/catch statement as follows, Code: try { That was all added in the if statement, so it should all look like, Code: if (SystemTray.isSupported()) { Congratulations, your finished! That wasnt so hard now was it. Theres also many other cool things you can do with this API, find more information here, http://java.sun.com/javase/6/docs/api/java/awt/TrayIcon.html I have provided you with a cool little application that shows the different uses assosciated with events using the System Tray API. Download it here, (includes src) http://uppit.com/v/4SGZNWS9 Enjoy! ~ Anthony |