aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Any one Can help me with Focus system? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Any one Can help me with Focus system?" Watch "Any one Can help me with Focus system?" New topic
Author

Any one Can help me with Focus system?

Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi All,

I am just trying to make a login form for my application which has username text field and password text field. the application is a touch screen application, so I am just planning to make a on screen key board with login form in the same screen something like the attched picture

My problem is: how to define action listener for each button. I don't have any idea at all.

if someone can help me please, I would appreciate it

Thnx




[Thumbnail for Picture1.png]

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

Recommended reading: http://download.oracle.com/javase/tutorial/uiswing/events/actionlistener.html

You might want to edit your post title, as it is inconsistent and a bit misleading with the actual question.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
HI Manish

Many Thanks for the Link, I know about action listeners and I know how to prgram the fuctions for a button, when you click on it.

the problems is with the focus on component. for example all I know is: when you click on a button it does TextField1.setText = button.getText() some thing like this.

the problem is I want the text to be writen in a textField where the cursor is. not to mention the name of textfields. like textfield.setText ..................

thanks for replying, but I think the title matchs my problem, which is focusing and sending the buttons text to the focused point.

Cheers
Farhad
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

HI Manish

Manish Maneesh

the problem is I want the text to be writen in a textField where the cursor is. not to mention the name of textfields. like textfield.setText ..................

textField.setText(textField.getText()+charToBeWritten()) where char to be written would depend on which button the user pressed.

but I think the title matchs my problem, which is focusing and sending the buttons text to the focused point.

Not really. Your title is
Any one Can help me with Focus system?
, whereas, in your post you asked
My problem is: how to define action listener for each button. I don't have any idea at all.



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Farhad Rahmati wrote:the problem is I want the text to be writen in a textField where the cursor is.


Then keep an instance variable whose type is JTextField. Any time a JTextField gets the focus, assign a reference to that JTextField to your instance variable. That way it will always point to the last text field which had the focus.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

javax.swing.text.TextAction#getTextComponent(java.awt.event.ActionEvent)

Note that the ActionEvent can be null.


luck, db
There are no new questions, but there may be new answers.
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Thank you very much Maneesh,

I will let you know, if I had any other problem regarding this issue
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi guys,

Thank you very much for your comments and your helps.

Specially Darryl Burke and Paul Clapham

I have tried both, I could manage to do it with Paul's comment. But I couldn't do that with TextAction.getTextComponent. I wish could do it, that's what I need

Becuase the method getTextComponent is protected and I could not find a way to use. I hope to do so.

if you guys have any idea please let me know.

but still it's working only in one window, but I want the on screen key board in a separat window not focusable. becuase I want the cursor should be in the focused TextBox. when you click the button in the On Screen Key Board Window. the should be writen in the text box where the cursor is in a different without. (SOMETHING LIKE WINDOWS SCREEN KEYBOARD)

Thanks again Paul and Darryl for your help, I appriciate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any one Can help me with Focus system?