Use Java to develop system pallets

Source: Internet
Author: User
Use Java to develop system pallets

 

@ For & ever 2009-11-27

Refer to the new system tray functionality in Java SE 6, web site http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray.
JDK must be in JDK 1.6.

To implement scheduled task resident System in recent projects, a friendly operation method can be provided to end users at the same time. Therefore, system tray is used. Jdk1.6 is used in the project, so refer to the example in the above article to modify it and add the required functions.

The post code is as follows:

<Br/> Import Java. AWT. awtexception; <br/> Import Java. AWT. image; <br/> Import Java. AWT. menuitem; <br/> Import Java. AWT. popupmenu; <br/> Import Java. AWT. systemtray; <br/> Import Java. AWT. toolkit; <br/> Import Java. AWT. trayicon; <br/> Import Java. AWT. event. actionevent; <br/> Import Java. AWT. event. actionlistener; <br/> Import Java. AWT. event. mouseevent; <br/> Import Java. AWT. event. mouselistener; </P> <p> Public linoleic SS systemtraytest <br/>{</P> <p> Public systemtraytest () <br/>{</P> <p> final trayicon; </P> <p> If (systemtray. issupported () {</P> <p> systemtray tray = systemtray. getsystemtray (); <br/> image = toolkit. getdefatooltoolkit (). getimage ("tray.gif"); </P> <p> mouselistener = new mouselistener () {</P> <p> Public void mouseclicked (mouseevent E) {<br/> system. out. println ("tray icon -Mouse clicked! "); <Br/>}< br/> Public void mouseentered (mouseevent e) {<br/> system. Out. println (" tray icon-mouse entered! "); <Br/>}< br/> Public void mouseexited (mouseevent e) {<br/> system. Out. println (" tray icon-mouse exited! "); <Br/>}< br/> Public void mousepressed (mouseevent e) {<br/> system. Out. println (" tray icon-mouse pressed! "); <Br/>}< br/> Public void mousereleased (mouseevent e) {<br/> system. Out. println (" tray icon-mouse released! "); <Br/>}</P> <p >}; </P> <p> actionlistener exitlistener = new actionlistener () {<br/> Public void actionreceivmed (actionevent e) {<br/> system. out. println ("exiting... "); <br/> system. exit (0); <br/>}< br/>}; </P> <p> popupmenu popup = new popupmenu (); <br/> menuitem defaultitem = new menuitem ("exit"); <br/> defaultitem. addactionlistener (exitlistener); <br/> Popup. add (defaultitem); </P> <p> trayicon = New trayicon (image, "tray Demo", popup); </P> <p> actionlistener = new actionlistener () {<br/> Public void actionreceivmed (actionevent E) {<br/> trayicon. displaymessage ("Action event", <br/> "An Action event has been peformed! ", <Br/> trayicon. messagetype. info); <br/>}< br/>}; </P> <p> trayicon. setimageautosize (true); <br/> trayicon. addactionlistener (actionlistener); <br/> trayicon. addmouselistener (mouselistener); </P> <p> // depending on which Mustang build you have, you may need to uncomment <br/> // out the following code to check for an awtexception when you add <br/> // an image to the system tray. </P> <p> // try {<br/> tray. add (trayicon); <br/>} catch (awtexception E1) {<br/> // todo auto-generated Catch Block <br/> e1.printstacktrace (); <br/>}< br/> //} catch (awtexception e) {<br/> // system. err. println ("trayicon cocould not be added. "); <br/>/}</P> <p >}else {<br/> system. err. println ("system tray is currently not supported. "); <br/>}</P> <p>/** <br/> * @ Param ARGs the command line arguments <br/> */<br /> Public static void main (string [] ARGs) <br/>{< br/> systemtraytest main = new systemtraytest (); <br/>}</P> <p>

 

 

 

A little thought:
Java cross-platform is good! This pallet program runs well on both Windows and Linux platforms.

I used to use C ++ to support both Windows and Linux. I found it very troublesome and gave up ....

@ Forandever 2009-11-27

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.