The Artima Developer Community
Sponsored Link

Java Answers Forum
why the event can't be processed?

1 reply on 1 page. Most recent reply: Jul 14, 2002 11:29 AM by Jay Kandy

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 1 reply on 1 page
he yunlong

Posts: 4
Nickname: javasea
Registered: Jul, 2002

why the event can't be processed? Posted: Jul 13, 2002 9:49 PM
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);
}
});
}
}


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: why the event can't be processed? Posted: Jul 14, 2002 11:29 AM
Reply to this message Reply
Works perfectly with v1.3.1_01. Dont see why it shouldnt on v1.4. Are you running with appletviewer?

Flat View: This topic has 1 reply on 1 page
Topic: An image in a panel Previous Topic   Next Topic Topic: How do I change editable JComboBox editable area?????

Sponsored Links



Google
  Web Artima.com   

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