This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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

Joined: Jan 18, 2013
Posts: 24

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: 2156
What is a "textbox"? I'm not aware of any Swing components by that name.
Ranjeet Deshmukh

Joined: Jan 18, 2013
Posts: 24

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

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

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

Joined: Jan 18, 2013
Posts: 24

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.
Similar Threads
JFrame one instance
Open multiple Terminals in one frame
Exporting .jars from Eclipse
layered Pane issues
b1.addActionListener( this);