This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes tray icon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "tray icon" Watch "tray icon" New topic

tray icon

Domenic Horner

Joined: Aug 21, 2009
Posts: 2
hey, guys, my first thread here

okay i am tryign to make a tray Menu, and i have somethign like this:

to listen for my actions
as we all know that created another class file called [classname$1.class,

is there any way to make anothher class to deal with the events and implement actionlistner there instead of creating sub-classes?

i tried this but faild

and then this in my other class (that implements actionlistner)

thanks guys

Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

Any class can implement ActionListener, as long as they implement the actionPerformed method. The following (ugly) way is too often used:
However, the ActionListener per, well, action is a lot better.

How To Ask Questions How To Answer Questions
Domenic Horner

Joined: Aug 21, 2009
Posts: 2
but is there any way of putting it so that the class does not create a sub-class (cuz its gets messy when you have 10+ listners)
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

My example code will work without any other classes. However, what do you prefer - 10 if-statements, or 10 classes that are each specialized to do only one single task?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60752

Please use real words when posting to the forums. Abbreviations such as "coz" in place of "because" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

JavaRanch sheriff

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: tray icon
Similar Threads
questions regarding system tray and tray icon
How to Add a Systemtray Icon on several machines ?
mulitple file selection using JFileChooser problem
Error loading image jar
reduce display frame SystemTray