|
| ||||||||||
| Tags: actionperformed, actions, java, setaction, tool bar button |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| How to use Actions in Java?
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. |
|
#2
| ||||
| ||||
| 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 |
|
#3
| ||||
| ||||
| 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 :
|
|
#4
| ||||
| ||||
| 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); |
|
#5
| ||||
| ||||
| 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);
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |
| Sliders actions in Fight Night Champion | Elucidation | Video Games | 5 | 08-03-2011 09:26 AM |
| 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 |