Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why can't setText overwrite my JTextArea?  RSS feed

 
Francis Tan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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!
 
Carey Brown
Saloon Keeper
Posts: 2840
43
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out Javadocs for JTextArea.append(String)
 
Knute Snortum
Sheriff
Posts: 3942
92
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Fred Kleinschmidt
Bartender
Posts: 555
9
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!