Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting input in textbox.

 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a "textbox"? I'm not aware of any Swing components by that name.
 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry Rob,

I wanted to say Text field that shows the inputs and result of computation for calculator.
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...)
 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic