Results 1 to 18 of 18
- 09-23-2010, 06:12 PM #1
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
How to dispatchEvent(KeyEvent evt) to an applet
First off, I apologize for not having an SSCCE code snippet. In the case that we do need one, I will create one :)
My question & scenario: I have an Applet that I want to send mouse and key strokes into. I studied that dispatchEvent could do the job, but it requires a KeyEvent object. I'm not sure what to place where. In the end, it can send mouse and keystrokes even when the applet's window is minimized. I also want it at the point where I can send the letter 'a' like this:
sendKey('a');
Do i need to add a actionlistener or keylistener to an applet? If so, how? Thank you very much :)
PS: I looked all over the forums, but could not find anything on this very subject.
- 09-23-2010, 07:50 PM #2
Are you saying you want to create new Event objects of those types and pass them to the components in the Applet via its event queue without actually involving moving the cursor or pressing on the keyboard?I want to send mouse and key strokes into
- 09-23-2010, 09:26 PM #3
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
thanks for your reply Norm,
Yes, I that is precisely what I want
- 09-23-2010, 09:44 PM #4
You didn't ask any further questions, so I'll assume you know how to do it
- 09-23-2010, 10:34 PM #5
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
I dont know how to do it. I guess based off what you said two posts earlier, I will change my question: how can i send text and mouse movements to an applet?
- 09-23-2010, 11:03 PM #6
Those are sort of vague requirements. Can you be more specific?
Is there a component in the applet that you want to receive text? Like a text field?
And what about the mouse movements? What component is to receive them and what will it do with them?
What class is sending these events and how is it related to the applet?
- 09-24-2010, 12:14 AM #7
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
The applet is a game, so there aren't other components in it. As for the mouse, I wanted to send mouse movements/strokes (not using the main mouse) to this Applet named "applet".
I heard you could use applet.dispatchEvent(KeyEvent evt), but I'm not sure where to go from there.
- 09-24-2010, 12:26 AM #8
Interesting. All GUI is built from java components.there aren't other components
What class/program do you want to send these events and how is it related to the applet?
- 09-24-2010, 12:33 AM #9
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
Suppose I have a class named "MouseHandler". Inside is a method named "sendStringToApplet(String text)". Inside this method, it dispatches an event to the static Applet "applet" in the AppletGUI class. For example, The applet is already open, so i run the method "sendStringToApplet("hello world!");". It should be able to send text to the applet. Where the text goes in the Applet does not matter for this conversation, Trust me :). So how can i get this method to work?
- 09-24-2010, 02:07 AM #10
That makes no sense at all. I have written dozens of applets that you could "send" a message to and the applet would completely ignore it. They have no listeners for any text messages.Where the text goes in the Applet does not matter for this conversation
So why send a message if there is nothing/no one to receive it?
Please explain.
- 09-24-2010, 04:44 PM #11
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
The applet is a game that uses its gaming engine to draw out objects. java.awt.Robot worked with sending keys and moving the mouse, which proves it works. But I can't use robot in my case because It will disrupt normal computing.
- 09-24-2010, 04:48 PM #12
You still have not explained the relationship between the code you want to write and the applet code. Does your code load the applet's classes and call its methods in the same JVM?
Does the applet run from an HTML page in a browser and your code is a separate desktop app?
Please explain.
- 09-24-2010, 06:04 PM #13
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
[quote = Does your code load the applet's classes and call its methods in the same JVM? [/quote]
Yes, I load it from an external URL, and it displays on my desktop application. This is all from the viewpoint of my Desktop application.
- 09-24-2010, 06:58 PM #14
By loading the Applet I meant, does your code create an instance of the applet using the new statement. Something like the following:
Applet theApplet = new THEAPPLET();
Then your code calls the applet's methods:
theApplet.init();
theApplet.start();
etc
Do you have a classloader that reads the jar file with the class files from the URL and loads the classes from that jar file or what does your code do to "load" the applet?I load it from an external URL, and it displays on my desktop application.
Your desktop application provides the window/frame that the applet displays in.
- 09-24-2010, 08:15 PM #15
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
- 09-24-2010, 08:37 PM #16
Can you get references to the components you want to send events to?
Here is a technique I used to send an ActionEvent to a component to simulate pressing Enter:Java Code:Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent( new ActionEvent(src, // the component to get the event ActionEvent.ACTION_PERFORMED, "Enter"));
- 09-24-2010, 09:59 PM #17
Senior Member
- Join Date
- Jul 2010
- Posts
- 124
- Rep Power
- 0
Thanks Norm. I set the applet to be static so I wouldn't have to instantiate it. So now, for the "src", i use AppletUI.applet. Now, how about mouse movements? And can I replace "Enter" with "A" if i want it to send a? Or how does it work? Do i need to attack a keylister to the applet and dispatch the event?
- 09-24-2010, 10:43 PM #18
Similar Threads
-
Help in KeyEvent
By chyrl in forum AWT / SwingReplies: 15Last Post: 05-26-2010, 08:12 AM -
JOptionPane KeyEvent
By mine0926 in forum NetBeansReplies: 5Last Post: 05-05-2010, 02:03 AM -
How can i use keyevent even tho the program isnt selected?
By Addez in forum New To JavaReplies: 11Last Post: 12-25-2009, 10:30 PM -
Brainbox needed -- KeyEvent VK_* constants stable??!
By Spiller in forum AWT / SwingReplies: 0Last Post: 08-17-2009, 03:59 PM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks


Bookmarks