Re: JButton event handling.
Code :
the same cancel button will need to invoke different code.
you mean 1 source for different commands?
i hope this will help you
Code :
cancelButton.setActionCommand("Your first string command here");
cancelButton.setActionCommand("Your second string command here");
cancelButton.setActionCommand("Your third string command here");
in your interface class(actionlistner)
Code :
if(event.getActionCommand.equalas("MyFirstCancelCommand") {
// do the task;
}
else if (event.getActionCommand.equals("MySeconCancelCommand") {
// do the taskl
}
// so on...
the event will get the action command, it must be equal to the "String" command that you set in your button.
Re: JButton event handling.
Thank you, that looks like the solution I need. I thought I`d read about something like this, but there`s so much to remember about Java !
OK, another thought/question, as this is the first time i`ve programmed with Swing/actionEvents.
How often, and when do these "actionEvents" occur ? If I have a method executing, and the user clicks on an enabled JButton, at what point does the code to handle the event get executed ? If required, is there a way to disable or ignore events while some critical processing is taking place ?
I`ve got so many questions ! I`d like to know about making JButtons invisible, instead of disabling them. The problem I have is that I am using a simple Java IDE (BlueJay), as Eclipse/NetBeans are too daunting for me at the moment. However, I am using the NetBeans GUI designer to create the layout for my JPanel(s). I`m probably being a bit "naughty", but I`m simply copying and pasting the NetNeans generated source code into my BlueJay project. If I then add my own code to make a JButton invisible, it messes up the layout, as NetBeans has generated code that places the components in positions relative to each other.
Any suggestions for an easier/better way for me to design GUI layouts graphically and to generate the Java source code for my applications ? I suppose I`m looking for a simple IDE with GUI design features built in, if such a thing exists.
Re: JButton event handling.
Quote:
How often, and when do these "actionEvents" occur ? If I have a method executing, and the user clicks on an enabled JButton, at what point does the code to handle the event get executed ? If required, is there a way to disable or ignore events while some critical processing is taking place ?
- Threads and Swing , Event dispatching thread - Wikipedia, the free encyclopedia , Lesson: Writing Event Listeners (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Quote:
I`m looking for a simple IDE with GUI design features
- netbeans is your way sir, as far as I know netbeans is the only IDE that can provide rich features regarding with GUIs, you might also look for Eclipse IDE.
For layouts have a look at this - Using Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
theres also another way for setting your components manualy l (i.e setting their locations and dimensions manually - Doing Without a Layout Manager (Absolute Positioning) (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
but i suggest try to study layouts, because you might need those for your future complex demands in your GUIs
for example: im currently writing a program , an application that uses JFrame, in that frame I have a scroll pane that divides two panels, the logic for the scroll pane is If i move the scroll Up the components on the north side will "Shrink" then the components on the south side will expand, respectively, but I am not "Able" to do this because I didnt use and studied any layouts... so i would suggest you study basic layouts that sun provides, I've already gave you the link sir.. I hope it helped you ...
happy coding..
Re: JButton event handling.
Thanks,
Looks like there`s no short cut...... back to the books/articles for me.
I`m finding that to really learn to code, I have to practice coding, and when I start to code I realise that I haven`t learned enough !
Re: JButton event handling.
so do I.. I know how and what you feel sir... I thought I learned "A lot" but its not "Enough" .
happy coding...
Re: JButton event handling.
I want to share this too sir.. lots of sample codes Swing JFCJava