wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Program is not doing what it is suppose to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Program is not doing what it is suppose to" Watch "Program is not doing what it is suppose to" New topic
Author

Program is not doing what it is suppose to

Stephen Norris
Ranch Hand

Joined: Oct 27, 2003
Posts: 44
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

Joined: Jul 03, 2001
Posts: 2120
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.


SCJP2. Please Indent your code using UBB Code
Stephen Norris
Ranch Hand

Joined: Oct 27, 2003
Posts: 44
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Stephen Norris
Ranch Hand

Joined: Oct 27, 2003
Posts: 44
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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

Joined: Oct 27, 2003
Posts: 44
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

Joined: Oct 27, 2003
Posts: 44
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program is not doing what it is suppose to
 
Similar Threads
Simple program question
Need Help Please
need help! (one error)
Need Help Please
Need Help Please