Results 1 to 1 of 1
-
AWT - catching click button event
Presented below is an example for catching button click event in AWT.
Java 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. } } }
Similar Threads
-
addActionListener(java.awt.event.ActionListener) in java.awt.Button cannot be applied
By mathias in forum Java AppletsReplies: 3Last Post: 03-26-2009, 10:31 PM -
Swing - catching click button event
By Java Tip in forum Java TipReplies: 0Last Post: 03-11-2008, 11:03 PM -
How to perform some event to button click
By eva in forum AWT / SwingReplies: 2Last Post: 01-16-2008, 12:27 AM -
how to click a jbutton and open an url
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:44 PM -
Click Framework 1.3
By levent in forum Java SoftwareReplies: 0Last Post: 06-09-2007, 08:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks