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.
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.
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
Joined: Jun 15, 2008
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?
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
Joined: Jun 15, 2008
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.
Joined: Oct 13, 2005
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.