• 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

Program is not doing what it is suppose to

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic