Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2008, 12:03 AM
Moderator
 
Join Date: Nov 2007
Posts: 1,637
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Swing - catching click button event
Presented below is an example for catching button click event in Swing.

Code:
public class TestEventSwing extends JApplet implements ActionListener { JButton b1, b2; JTextField t1; public void init() { setLayout(new FlowLayout()); t1 = new JTextField(30); b1 = new JButton("Output"); add(b1); add(t1); b2 = new JButton("Fire event 1st button"); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { t1.setText("first button clicked"); } if (e.getSource() == b2) { // from the b2 button, we trigger a click on the b1 button. // As an added bonus, a visual effect on b1 is visible! b1.doClick(); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
AWT - catching click button event Java Tip Java Tips 0 03-12-2008 12:02 AM
NetBeans, Swing Initialization Event ? Cero.Uno New To Java 0 02-09-2008 04:29 PM
How to perform some event to button click eva AWT / Swing 2 01-16-2008 01:27 AM
addActionListener(java.awt.event.ActionListener) in java.awt.Button cannot be applied mathias Java Applets 1 08-06-2007 09:49 AM
Click Framework 1.3 levent Java Announcements 0 06-09-2007 09:27 AM


All times are GMT +3. The time now is 09:28 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org