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:02 AM
Moderator
 
Join Date: Nov 2007
Posts: 1,637
Java Tip will become famous soon enoughJava Tip will become famous soon enough
AWT - catching click button event
Presented below is an example for catching button click event in AWT.

Code:
public class TestEvent extends Applet implements ActionListener { Button b2, b1; TextField t1; public void init() { setLayout(new FlowLayout()); t1 = new TextField(30); b1 = new Button("Output"); add(b1); add(t1); b2 = new Button("Fire event 1st button"); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { t1.setText("1st button clicked"); } if (e.getSource() == b2) { // from the b2 button, we creating an event to trigger a click // on the b1 button ActionEvent ae = new ActionEvent((Object)b1, ActionEvent.ACTION_PERFORMED, ""); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ae); // b1.dispatchEvent(ae); can be used too. } } }
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
Swing - catching click button event Java Tip Java Tips 0 03-12-2008 12:03 AM
How to perform some event to button click eva AWT / Swing 2 01-16-2008 01:27 AM
how to click a jbutton and open an url katie AWT / Swing 1 08-06-2007 11:44 PM
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 12:51 PM.


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