Results 1 to 7 of 7
Thread: How to Use Actions
- 04-18-2010, 07:41 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 59
- Rep Power
- 0
How to Use Actions
Hello. I have spent quite a few hours trying to follow an API on how to use Actions in a java program.
I have 3 JButtons and have just added a JMenu. What I want to do is to add an ACTION so that the JMenu performs the same function as the JButtons. (i.e. they both do the same thing).
I have tried to copy and follow the example from the API forum.
How to Use Actions (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
The first error I get in compiling is on the following line:
Action loadFile = new LOADFILE();
However, I get the following error message:
softeng2final2.java:49: cannot find symbol
symbol : class LOADFILE
location: class softeng2final2
Action loadFile = new LOADFILE();
^
When I later define LOADFILE
LOADFILE= new AbstractAction(null,null){
I get the error message:
softeng2final2.java:108: cannot find symbol
symbol : variable LOADFILE
location: class softeng2final2
LOADFILE= new AbstractAction(null,null){
^
Please can anyone help???:eek:
- 04-18-2010, 07:46 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 04-18-2010, 08:25 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 59
- Rep Power
- 0
Why can't it find it? It's very visible to me!!
-
- 04-18-2010, 10:03 PM #5
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 11
I have tried to copy and follow the example from the API forum.
How to Use Actions (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
http://java.sun.com/docs/books/tutor...ctionDemo.java
When I run that code I have this notification:
Resource not found: toolbarButtonGraphics/navigation/Back24.gif
Resource not found: toolbarButtonGraphics/navigation/Up24.gif
Resource not found: toolbarButtonGraphics/navigation/Forward24.gif
- 01-02-2015, 01:30 PM #6
Member
- Join Date
- Dec 2014
- Posts
- 1
- Rep Power
- 0
Re: How to Use Actions
This IS the best way to handle all images and icons in a JAR App.
Once you've zipped up all of your images and icons into its own JAR file - Configure your build path by adding the images JAR file into your libraries tab so that its now included in your classpath.
Then simply use the following 3x lines of code at the start of your constuctor to access any image you need for anything including a SystemTray image which doesn't accept the simple ImageIcon's as its main icon (weird I know). The 3x lines are:
URL iconUrl = this.getClass().getResource("/image-iconb.png");
Toolkit tk = this.getToolkit();
someimgicon = tk.getImage(iconUrl);
(someimgicon is just a constructor declared Image variable)
Now you can set a window icon as simply as:
setIconImage(someimgicon);
and at the same time use the same variable when setting the System TrayIcon by declaring:
trayIcon = new TrayIcon(someimgicon, "SystemTray Demo", popupMenu);
The above allows you to declare Images or ImageIcons easily and centrally without running the risk of not keeping image resources in the right place. It keeps it nice and tidy, with the JAR containing all your images automatically compiled at run time and distribution of your program.
As a bonus, once the JAR is registered in your classpath - you can keep adding any other images into the same JAR at any time without any fuss too - Everything just works and the added images are instantly available to your app.
Much better in my view.Last edited by webasylum; 01-02-2015 at 01:33 PM.
- 01-02-2015, 01:52 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Similar Threads
-
JMenuItems and actions
By Kligham in forum New To JavaReplies: 5Last Post: 01-05-2010, 06:00 PM -
Button Actions
By vasavi.singh in forum Advanced JavaReplies: 3Last Post: 04-03-2009, 10:50 PM -
various actions in menuitem of popupmenu
By Peggy in forum Java AppletsReplies: 0Last Post: 12-11-2008, 12:50 PM -
Actions
By alley in forum AWT / SwingReplies: 2Last Post: 01-16-2008, 03:52 PM -
Bean related actions in JSP
By Java Tip in forum Java TipReplies: 0Last Post: 12-24-2007, 11:04 AM
Bookmarks