Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 29 of 29

Thread: How to set a button event trigger?

  1. #26
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: ActionEvent

    Quote Originally Posted by hooshdar3 View Post
    Heh!unbelievable!I haven't done that!

    OK, I added that line, and now get the compile error:
    Woah, confusing thread.

    I suspect you don't really understand the difference between a class and an object. When you define a variable or method as static you are saying it belongs to the class, not an instance of that class. The this keyword reference the object. Because simulate() is defined as static it doesn't belong to an instance of an object.

    To remedy this use a constructor and create an instance of sysinfoHooshi in the entry point.

    public static void main(String[] args) {
        SysInfoHooshi sysInfoHooshi = new SysInfoHooshi();
        sysInfoHooshi.simulate();
    }

  2. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    hooshdar3 (July 16th, 2014)

  3. #27
    Member
    Join Date
    Mar 2014
    Posts
    70
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: How to set a button event trigger?

    But what if I have more buttons?
    I have 1 HButton, named 'button' on a 'JDialog' named 'dialog', and anotther JButton named 'queryButton' on a 'JDialog' named 'queryDialog'.
    I changed the actiomPerformed() function thus:
    	 public void actionPerformed(ActionEvent e) {
    		 if(e.getSource() == button)
    		    dialog.setVisible(false);
    		 if(e.getSource() == queryButton)
    		    queryDialog.setVisible(false);
    	}
    It seems that this should be working now, but the second "if" doesn't work What is the problem?

  4. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set a button event trigger?

    but the second "if" doesn't work What is the problem?
    Can you explain what "doesn't work" means? Is the method called? Add a println() statement that prints out the value returned by the getSource() method to see what component is causing the event and the call to the method.

    NOTE: if statements should use {} to enclose the statements that they control. Both if statements are missing their {}s.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #29
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to set a button event trigger?

    I'm going to close this thread, because it's more of the same already going on in his other threads which have been combined into one. We've moved on but not very far.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 3
    Last Post: September 26th, 2013, 12:29 PM
  2. Button event handler from another class
    By Scorliss in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 6th, 2013, 06:41 PM
  3. Problem netbeans gui button event handling
    By hiepa in forum AWT / Java Swing
    Replies: 7
    Last Post: December 3rd, 2012, 05:24 PM
  4. How to set cancel button ASAP please
    By smasm in forum Object Oriented Programming
    Replies: 1
    Last Post: October 1st, 2011, 08:29 AM
  5. Trigger Button in Html
    By liron in forum Java Networking
    Replies: 1
    Last Post: October 16th, 2010, 09:17 AM