CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2007
    Posts
    25

    [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
    }

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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.

  3. #3
    Join Date
    Oct 2007
    Posts
    25

    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

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    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
    Please use &#91;CODE]...your code here...&#91;/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
  •  





Click Here to Expand Forum to Full Width

Featured