[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
}
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.
Re: Running a JButton automatically
Quote:
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
Re: Running a JButton automatically
Quote:
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