How to input text from a swing on screen keyboard to another swing JFrame - swing

I have a swing on screen keyboard that can be used to send key presses to the other JFrame but it is not focusing on the JTextField.
Should I put jtextfield.requestfocus in every key so it should work?
Note:
The Input JFrame calls the keyboard Swing and passes the JTextField instance for focus request

When you create your keyboard frame you can use:
frame.setFocusableWindowState(false);
This should prevent the window from receiving focus to focus will remain on the other window.

Related

Adding a limit to how often you can press a button in as3

I'm coding a game for Android on Flash using AS3. My problem is that when I shoot a rocket or bullet at an enemy the user can repeatedly press the virtual button (on screen), this defeats the object of the game. Is there any way to limit how often a user can press this button so it can be pressed every half second or so? Many Thanks. (will provide code upon request if needed)
In the event handler that handles the button press, remove the listener.
This alone would disable the button.
Additionally, start a Timer.
Upon completion of the timer, re-add the listener for the button press, which allows pressing the button again, but only after the timer completed.

Why do I have to click the movie for my character to respond?

My movie has 3 frames, first one is the welcome screen with the play button, and after I press it and jumped to frame2 I have to click the movie for my character/player to respond and move by arrows. Same happens if I go back to frame2 from my game-over screen placed on frame3.
I use gotoAndPlay(); to navigate frames, naturally.
if it's something having to do with my code from frame2 i will post what it is required. I'd like to know why is that happening and how to fix it. THANKS!
Clicking your character gives it focus.
Only* what has focus receives keyboard events.
If you register the listener for the keyboard event on your character object, you have to click it first, before it receives those events.
However, the KeyboardEvents bubble up the display list and eventually reach the top most container which is the stage. This gives you two options:
Handle the focus yourself by assigning the object that should have focus to the stage.focus property. This is basically doing what the clicking does in your current situation.http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#focus
register your listeners at the stage
The user simply needs to click anywhere on the flash stage to add keyboard focus. Normally, a good way of achieving this is by using a start button, or something similar, for that first bit of mouse/keyboard focus.

Window not selected after changing frame from using a button

When I change scene with the use of a button in my game it seems to deselect the window. Then it does not respond to keyboard input without clicking the window again afterwards.
Is there a way to stop this with some sort of command or a way to bypass this with a different method.
When you click an object that object gains focus. During your buttons MouseEvent.CLICK event listener, you need to call the setFocus() function on the object you need the key strokes on.

Action Script 3 keyboard event set focus

I set focus to a text field in the init method, however keyboard enter event only works when I click the text field first.
What is the problem?
It's because, in AS3, by default, stage got the focus. So if you are adding a keyboard event listener to anything other than stage you have to set focus to that object.
Example,
If txt is your text field, you are adding a keyboard event listener to txt then you must do get focus for that like
stage.focus = txt;
That line brought focus to the text field but remember if you click on anything other than that, that object got focus. Needless to say, txt lost focus.
Tip: Try using adding keyboard event listener to stage, if you do so then it dispatches the event when a key is clicked or released regardless of the what object has focus.
stage.addEventListener(KeyBoardEvent.KEY_DOWN, onKeyDown);

How can I press a swing JButton using mouse events?

I Have a JButton (or any Component, really) that I would like to trick into thinking that it has been clicked on and therefore firing its action performed event. I don't want to call the action performed or doClick directly because I am trying to make a solution that generalizes beyond buttons, and I am constrained to posting events.
I would have thought that posting a MousePressed event to the system event queue would have done it, but no. ( with appropriate location, click count etc.)
Then I thought a mouse entered followed by a mouse move, a mouse pressed, a mouse released, and a mouse clicked, but no.
None of this causes the JButton to fire its action performed like it does when I actually click on it.
Has anyone caused a JButton to spit out its action performed event by driving it with mouse events? Moved a JSlider with mouse events? Expanded a tree node?
Thanks for any help.
Have you tried the fireActionPerformed method? I can't off the top of my head now remember if all components have it but if i remember right, all buttons and menu items should deifnately have it. Just a thought