The Artima Developer Community
Sponsored Link

Java Answers Forum
generate awt event

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
he yunlong

Posts: 4
Nickname: javasea
Registered: Jul, 2002

generate awt event Posted: Jul 13, 2002 8:59 AM
Reply to this message Reply
Advertisement
these code are from <<Graphic Java 1.2 Mastering the JFC Volume I:AWT>>, I want to simulate the action of buttong-clicking, but I can't see the result, I am using jdk1.4

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class TestApplet extends Applet {
public void init() {
final Button
button1 = new Button("other button activates me"),
button2 = new Button("press me");

add(button1);
add(button2);

button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showStatus("button 1 activated");
}
});

button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MouseEvent press = new MouseEvent(
button1,
MouseEvent.MOUSE_PRESSED,
System.currentTimeMillis(),
0, 5, 5, 1, false);

MouseEvent release = new MouseEvent(
button1,
MouseEvent.MOUSE_RELEASED,
System.currentTimeMillis(),
0, 5, 5, 1, false);

button1.dispatchEvent(press);

try {
Thread.currentThread().sleep(50);
}
catch(InterruptedException ex) {
ex.printStackTrace();
}

button1.dispatchEvent(release);
}
});
}
}

Topic: Help with Data exchange Previous Topic   Next Topic Topic: Voodoo Exam - Be a part of it !

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use