File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButtons and JTextArea

 
Marcio Portillo
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to make a cash register application.
I have the graphics pretty much down, that code I get.
Can anyone help me with the actions?
I want to be able to click on a button and write text to the text area.
I've seen code for simple click the button and text appears, but the problem with that is it rewrites the whole text area.
Let me explain, I want to click a button named pizza every time I click I want the text area to write "Small Pizza $5.00", if I press it twice the new text would be "2 Small Pizzas $10.00", and so on...
I want to be able to not have it refresh the text area but keep adding to the text already in there.
If I have "2 small cokes $2.00", I want "2 small pizzas $10.00" to be written under or over it.
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marcio Portillo , welcome to Javaranch,
to get your task done, you need some remembering logic in the button code so as to know what was the last displayed item.
Thats one thing and another is that, you can append text to a textarea rather than set new text to it. It works perfectly fine.



Hope this helps
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marcio Portillo:

I've seen code for simple click the button and text appears, but the problem with that is it rewrites the whole text area.


I'm assuming that this code is calling setText on the JTextArea. If you call append instead, it should do exactly what you want.
 
Marcio Portillo
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks , guys.
I did see an example that used append, didn't try it though.

What would I have to look for as far as the button code?

Any examples of how it can be accomplished?

what would i google for JButtons or java logic examples?

For example:

if (mouseclick == 1){
append.JTextArea("Small Pizza $5.00");
}else (mouseclick == 2){
append.JTextArea("2 Smalll Pizzas $10.00");
}
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess its pretty hard to get exact logic to cater your needs.
Why don't you write one yourself .

And please dont ask for logic or code here because we dont do your home work.


Hope this helps
[ June 16, 2008: Message edited by: Amit Ghorpade ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 47295
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marcio Portillo:
Thanks , guys.

if (mouseclick == 1){ . . .
}else (mouseclick == 2){ . . .
}

Not object-oriented programming; you want the details to be in the object you click on, not in the button. So you want a Pizza object with a price in. And don't use floating-point arithmetic for prices.

And welcome to JavaRanch
 
Marcio Portillo
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where can I find the forum rules for posting code?
Want to place mine, so you guys can help me out, not do my homework, but get me in the right direction.


Thanks for the help so far.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47295
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marcio Portillo:
Where can I find the forum rules for posting code?
Thanks for the help so far.
Here. We are happy to see code, but make sure to use the CODE tags which make it easier to read.

And Amit Ghorpade, please go easy on Marcio. Remember he is new here.
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Amit Ghorpade, please go easy on Marcio. Remember he is new here.

Yes sir

I always go easy with everyone whether old or new
And please dont ask for logic or code here because we dont do your home work.

as in my above post I have requested him because I felt like he was asking for logic for his task.

Please dont misunderstand me Campbell Ritchie :roll:



Always glad to help
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic