Results 1 to 5 of 5
  1. #1
    geckolux is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default Call action of JButton from another class

    HY

    i would like to ask if it is possible to perform the actions when you click a JButton(actions described in add action listener) from another class.
    So like interface.jButton.press smth like that.

    thx

    gecko

  2. #2
    Abdul Ajis is offline Member
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Default

    Possible

    implements action listener in the new class

    and give that referece in the button addActionListener

  3. #3
    MrNice is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Default Re: Call action of JButton from another class

    What about with getsource, canno't figure it out...
    JButton and ActionListener (action listener in different class/.java file).

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Call action of JButton from another class

    If you have a reference to the button you can do:

    Java Code:
    button.doClick();

  5. #5
    MrNice is offline Member
    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Default Re: Call action of JButton from another class

    I wanted to use hasmap, but dont know how to do it. I got gui in 1 file, i wanted to have a action listener in 2 file, and in other files imported functions in actionlistener.

    It look like i need references to all Jframe/dialog components.

Similar Threads

  1. action class
    By jayagowri in forum Web Frameworks
    Replies: 1
    Last Post: 05-07-2008, 03:23 PM
  2. Action class in Struts
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-27-2007, 10:05 AM
  3. Few action in one Jbutton
    By kubiasty in forum New To Java
    Replies: 0
    Last Post: 07-25-2007, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •