aspose file tools*
The moose likes Beginning Java and the fly likes JButtons and JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JButtons and JTextArea" Watch "JButtons and JTextArea" New topic
Author

JButtons and JTextArea

Marcio Portillo
Greenhorn

Joined: Jun 15, 2008
Posts: 3
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

Joined: Jun 06, 2007
Posts: 2718
    
    6

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


SCJP, SCWCD.
|Asking Good Questions|
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Marcio Portillo
Greenhorn

Joined: Jun 15, 2008
Posts: 3
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

Joined: Jun 06, 2007
Posts: 2718
    
    6

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

Joined: Oct 13, 2005
Posts: 40061
    
  28
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

Joined: Jun 15, 2008
Posts: 3
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

Joined: Oct 13, 2005
Posts: 40061
    
  28
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

Joined: Jun 06, 2007
Posts: 2718
    
    6

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
 
subject: JButtons and JTextArea