Results 1 to 4 of 4

Thread: How to handle JButton Click Event in Java Swing

  1. #1
    Join Date
    Dec 2011
    Posts
    69

    How to handle JButton Click Event in Java Swing

    Hi friends I am new to java Swing and however I just want to know the possible way to manage and handle multiple buttons events in one program, I have try many tricks but still not clear with this concepts. If you guys have any of the information or any of the suggestion for this Event Handling then please let me know. Any of the reply is Thanks and appreciated

  2. #2
    Join Date
    May 2009
    Posts
    511

    re: How to handle JButton Click Event in Java Swing

    For handling the Button Events in Java you first have to import the java.awt.event package, and after that you have to implements the ActionListener Interface. After that you have to add the ActionListener to the particular buttons that you want to perform the Event. So to assign the ActionListener make use of addActionListener(); And after assigning you can handle those particular button with the help of the object.

  3. #3
    Join Date
    May 2009
    Posts
    637

    re: How to handle JButton Click Event in Java Swing

    According to my information you just try this out May it help you to Manage JButton Events in Swing
    Code:
    Public void actionPerformed(ActionEvent ae)
    {
    Object o= ae.getSource();
    if(o==btn1)
    {
    //Then perform statement 1;
    }
    If(o==btn2)
    {
    //Then perform statement 2;
    
    }
    If(o==btn3)
    {
    //Then perform statement 3;
    
    }
    }

  4. #4
    Join Date
    May 2009
    Posts
    539

    re: How to handle JButton Click Event in Java Swing

    There are several method are available for class JButton, by which we can handle the behavior and the properties of the instance of JButton class : so there are some of the following method are listed below by which you can control the events and other properties of JButton.
    setToolTipText(); // Used for setting setToolTipText
    setPressedIcon(); // Used to assign the image icon that display when the Button is pressed.
    setRolloverIcon(); // Used to display the rollover icons

Similar Threads

  1. Applets V/s Swing in JAVA
    By "Dritan" in forum Software Development
    Replies: 3
    Last Post: 14-12-2010, 09:04 AM
  2. JButton to send command to Java console
    By Fox28 in forum Software Development
    Replies: 6
    Last Post: 21-07-2010, 10:03 AM
  3. Java Swing and MySQL
    By shelton141 in forum Software Development
    Replies: 1
    Last Post: 22-09-2009, 08:50 AM
  4. How to invoke a form from a button click using Java Swing?
    By shelton141 in forum Software Development
    Replies: 1
    Last Post: 11-09-2009, 07:54 AM
  5. JButton does not work in java swing
    By RogerFielden in forum Software Development
    Replies: 3
    Last Post: 15-04-2009, 12:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,507,397.10496 seconds with 17 queries