Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program is not doing what it is suppose to

 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program is pretty much finished, but it is suppose to adjust a circle with a JSlider and all of that works. But at the same time, it is suppose to calculate the radius, diameter, area, and circumference and I move the JSlider. It gets everything right on the initial placement, but when i move the slider, nothing happens. The circle changes sizes, but no number changes. Can someone please help. Here is the first file and then the second file will be set off below the first.

 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen,
The constructor for Homework2a is executed oly once. There you write to the textArea. After the change listener sets the diameter of myWork you need code to update the content of the text area.
 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a constructor that updates that, or do i have to make a loop somewhere. I am not very familiar with this stuff and I am not very versed on this stuff.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd want to handle this in the ChangeListener. Create a routine which sets the text of the text area based on the diameter; call it to initialize the TextArea, and call it again from that handler to update the text.
 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if I move my JTextArea statement to the change Listener statement. Do you think that would work?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, not quite. You don't want to construct a new textarea on each event; just change the text. So you need to keep a reference to the textarea in a member variable, and then call setText() on it as appropriate. The argument to the call to setText could be essentially the same as the current constructor argument.
 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, that does not work. I am just fiddling with this and don't know what coding will work there. Just a student, and not good at this stuff at all.
 
Stephen Norris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking through my book and I can't find anything that relates to what we are discussing about getting the textArea to update itself. I am sure that it is in there, but could you or someone else give me another clue to help me find this. Most of the stuff that I am finding in the book renews the textArea each time that you compile the code, not when you just change a slider or some other sort of option.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic