aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Getting input in textbox. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Getting input in textbox." Watch "Getting input in textbox." New topic
Author

Getting input in textbox.

Ranjeet Deshmukh
Ranch Hand

Joined: Jan 18, 2013
Posts: 35

Hi all,

I'm trying to build calculator desktop application in netbeans. Problem is I'm not able to get many inputs in the text box (e.g- 123+456) by clicking on buttons(0,1---9, +, - ,*, / etc). Every time when I click on one(1) it get displayed but when I click two(2), one disappears. What shall I do?


~R@njeet.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2225
    
    8
What is a "textbox"? I'm not aware of any Swing components by that name.
Ranjeet Deshmukh
Ranch Hand

Joined: Jan 18, 2013
Posts: 35

sorry Rob,

I wanted to say Text field that shows the inputs and result of computation for calculator.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Again, what class is this "Text" field? Don't make us guess whether it's a JTextPane or a TextField or something else. Just tell us.
Ramesh Pramuditha Rathnayake
Ranch Hand

Joined: Oct 31, 2012
Posts: 175
    
    1

I will suppose that you have used JTextField...

In the actionPerformed() method I think you have writen:

You will see that this code only replace the text in the JTextField..
But you have to type 2 at the end of the text.

Therefore,
1. You have to get the text in the JTextField.
2. Then add 2 at the end of that text
3. Replace the text in JTextField with that text..

So, new code will be,


(I also have to say that, Don't make us to guess what is in your mind.. Use Class names correctly...)


Ramesh-X
Ranjeet Deshmukh
Ranch Hand

Joined: Jan 18, 2013
Posts: 35

Sorry Ramesh and Paul for not to be specific.

Thanks Ramesh That was helpful, it solved my problem. If there will be any I will post again & of course I will be specific next time.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting input in textbox.