Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Unhappy 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:

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,961
    Blog Entries
    7
    Rep Power
    22

    Default

    Quote Originally Posted by AJArmstron@aol.com View Post
    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:
    The compiler simply can't find the identifier LOADFILE, neither as a class (the first time it complained) nor as a variable name (the second time it complained).

    kind regards,

    Jos

  3. #3
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Default

    Why can't it find it? It's very visible to me!!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by AJArmstron@aol.com View Post
    Why can't it find it? It's very visible to me!!
    But it's not visible to us.

  5. #5
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    6

    Default

    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)
    I don't know did you noticed that you had full code on that page "ActionDemo.java" (I think you did). If you did not here is link:
    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
    that means everything is fine, but you don't have gif pictures Back24.gif, Up24.gif, and Forward24.gif. If you provide them you will not have any error.

  6. #6
    webasylum is offline Member
    Join Date
    Dec 2014
    Posts
    1
    Rep Power
    0

    Default 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.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,961
    Blog Entries
    7
    Rep Power
    22

    Default Re: How to Use Actions

    Erm, this thread is almost five years old; there is no need to revive it.

    kind regards,

    Jos

    ps. I'll close this old thread.
    I have the stamina of a seal; I lie on the beach instead of running on it.

Similar Threads

  1. JMenuItems and actions
    By Kligham in forum New To Java
    Replies: 5
    Last Post: 01-05-2010, 06:00 PM
  2. Button Actions
    By vasavi.singh in forum Advanced Java
    Replies: 3
    Last Post: 04-03-2009, 09:50 PM
  3. various actions in menuitem of popupmenu
    By Peggy in forum Java Applets
    Replies: 0
    Last Post: 12-11-2008, 12:50 PM
  4. Actions
    By alley in forum AWT / Swing
    Replies: 2
    Last Post: 01-16-2008, 03:52 PM
  5. Bean related actions in JSP
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-24-2007, 11:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •