|
-
March 27th, 2008, 06:53 AM
#1
[RESOLVED] Running a JButton automatically
Hi i want to be able to automatically activate a JButton and run the commands under that button when new button 'All Targets' is selected.
I have the following code, can anyone help?
Code:
JButton all_tar = new JButton ("All Targets");
all_tar.addActionListener(this);
JButton calcuate = new JButton ("Calculate");
calculate.addActionListener(this);
if (arg == "All Targets")
{
for (m = 100; m < 1000; m++)
{
tgetbox.setText(" " + (int)(m));
target = m;
//here is where i want to automatically activate another button
}
}
if (arg == "Calculate") //this is the button that i want to automatically activate numerous times
{ //instructions
}
-
March 27th, 2008, 07:16 AM
#2
Re: Running a JButton automatically
There are a few ways of doing this but probably the simplest is to call the button you want to activate's doClick() method which programatically clicks the button.
-
March 27th, 2008, 08:33 AM
#3
Re: Running a JButton automatically
 Originally Posted by keang
There are a few ways of doing this but probably the simplest is to call the button you want to activate's doClick() method which programatically clicks the button.
I don' t understand how you would implement doClick() with a button that i have created, i know you can use it easily when its a button being pressed on a keyboard using keyevent. Could you explain ?
thanks for the quick reply
-
March 27th, 2008, 08:47 AM
#4
Re: Running a JButton automatically
 Originally Posted by blaze12364
I don' t understand how you would implement doClick() with a button that i have created
You don't have to implement it, just call it - it's part of the AbstractButton interface: doClick().
That is the essence of science: ask an impertinent question, and you are on the way to a pertinent answer...
J. Bronowski
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|