Meaningless Drivel is fun!
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 Java Interview Guide 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

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?

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2454
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

Joined: Oct 14, 2005
Posts: 19973

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: 178

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.

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...)

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.
I agree. Here's the link:
subject: Getting input in textbox.
It's not a secret anymore!