Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to use Actions in Java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 14-02-2010
Member
 
Join Date: Aug 2006
Posts: 221
How to use Actions in Java?
  

Hi friends,
I have recently started doing java, so i am not having much knowledge about it. I have created an application in which i need to do the coding of the action. But i don't know anything about it. So i thought that posting here might help me.!! Can someone explain me how to use Actions in Java.?? Any coding related to the topic would be grateful.

__________________
AMD Sempron 2800+ @ 2Ghz
Asus A7V8X-LA
120Gb Seagate barracuda 7200Rpm Ultra-ATA 100
Elixir 512mb DDR Pc3200 (Soon 1Gb)
Club 3D Radeon 9600 256Mb
Lite-On Cd & Dvd writer combo
IDE-Dvd drive
400w Psu
Windows Xp Pro Sp2
Advent Wireless Mouse & Keyboard.
Reply With Quote
  #2  
Old 14-02-2010
Member
 
Join Date: Jul 2006
Posts: 289
Re: How to use Actions in Java?

If you are having two or more components which are performing the same function then you can use an Action object to implement the function. An Action can be used to separate functionality and state from a component. An Action object is an ActionListener that provides action-event handling. Along with that it provides handling of the text, icon and the buttons also. The state that an action can handle includes text, icon, mnemonic, enabled, and selected status.
__________________
Signatures reduce available bandwidth
Reply With Quote
  #3  
Old 14-02-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: How to use Actions in Java?

For attaching an action to a component, you will have to use the setAction method. The following things happen when you invoke setAction on a component :
  • The component's state is updated to match the state of the Action.
  • The component's state is updated to match the Action, if the state of the Action changes.
  • The Action object is registered as an action listener on the component.
Reply With Quote
  #4  
Old 14-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,844
Re: How to use Actions in Java?

The following snippet of coding is an example of creating a tool-bar button and menu item :
Code:
Action leftAction = new LeftAction(); 
...
button = new JButton(leftAction)
...
menuItem = new JMenuItem(leftAction);
Reply With Quote
  #5  
Old 14-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,946
Re: How to use Actions in Java?

The following example can be used for creating and instantiating an AbstractAction subclass :
Code:
leftAction = new LeftAction("Take left", anIcon,
             "This is the left button.",
             new Integer(KeyEvent.VK_L));
...
class LeftAction extends AbstractAction {
    public LeftAction(String text, ImageIcon icon,
                      String desc, Integer mnemonic) {
        super(text, icon);
        putValue(SHORT_DESCRIPTION, desc);
        putValue(MNEMONIC_KEY, mnemonic);
    }
    public void actionPerformed(ActionEvent e) {
        displayResult("Action for first button/menu item", e);
    }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use Actions in Java?"
Thread Thread Starter Forum Replies Last Post
Beyond compare 3 doing actions without asking user pele1200 Windows Software 3 13-08-2012 01:31 PM
how to use voice actions on Ice cream Sandwich Popeyee Portable Devices 9 14-12-2011 01:24 PM
Several buttons doing the same actions on different controls AbhayD Software Development 4 11-12-2009 08:28 PM
Multiple actions of a form Sadiee Software Development 3 29-06-2009 07:14 PM
Actions depending on the length of the press of a button Elijah Software Development 3 16-03-2009 10:40 AM


All times are GMT +5.5. The time now is 12:45 PM.