• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why can't setText overwrite my JTextArea?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I'm trying to make a very simple text-based solitaire game with gui, but the display won't work quite well.

The cards are supposed to be displayed in a certain text area after clicking the a button. However, after clicking the button twice, it doesn't overwrite the old contents in the text area.
Could anyone tell me what's wrong with my code? I'm fairly new to Java and in this forum so do feel free to critic my code, and try to bear with my terrible coding. Thanks!

Note: This is a shortened version of my code, highlighting the issue alone. Also, I'm not allowed to use LinkedList provided by the JRE, hence I'm manually making my own linked list.

My main class:


My piles class:


Here's an image (and link) of the result:

img

Any help would be greatly appreciated!
 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out Javadocs for JTextArea.append(String)
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class names should start with an uppercase letter, so, Test, TPiles, NCard, etc. And typically, class names should be singular, so, TPile.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks okay to me, in other words all I know is what you do see. You haven't explained what you expect to see instead.

Welcome to the Ranch... but do you really have to put your images on that site with the horrible spammy advertising links? It's kind of embarrassing to have the Ranch associated with that sort of thing.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You create a new ncard, assign it to head, create another ncard and assign it to rover, then you discard those and set both head and rover to null? So rover is always null, since I don't see anywhere that it is ever set to something else.
 
reply
    Bookmark Topic Watch Topic
  • New Topic