aspose file tools*
The moose likes Beginning Java and the fly likes Trying to change area textbox when value is changed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to change area textbox when value is changed" Watch "Trying to change area textbox when value is changed" New topic
Author

Trying to change area textbox when value is changed

Mack Grill
Greenhorn

Joined: Feb 27, 2012
Posts: 29

I'm trying to make an applet display the correct text in the area textbox when the value is changed.

I know that the answer lies in put the statement in the 'tf1' if clause but I don't know which method to use.

here are the instructions just in case:

"First, employ what you have learned about data encapsulation/hiding. Secondly, fix the applet so that if a user enters a radius and then presses Enter, the area text box will show the true area.

You also have a choice about the area text box. You can either make it so that if the user enters an area and presses Enter, the radius text box will show the new radius. Or, you can disable the area text box so data cannot be entered into it. The goal of this exercise is to make it so that the underlying class is not prone to data corruption by another class and the function of the applet is not prone to user data errors (what you see after the Enter key is pressed in a text box is a correct representation)."

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18129
    
    8

Mack Grill wrote:I'm trying to make an applet display the correct text in the area textbox when the value is changed.


I think the term "the value" is a bit imprecise, don't you agree? Especially since there isn't anything in your instructions which say to do something when something is changed. So I'm confused. Could you explain, in terms of those instructions, what part you're asking about?
Mack Grill
Greenhorn

Joined: Feb 27, 2012
Posts: 29

sorry

I mean when the radius of the circle is given a different set of numbers(4.0,5.0,..) and is calculated, the new total for area will also display in the textbox for area.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18129
    
    8

I don't see that anywhere in the requirements you posted. Am I missing something?
Mack Grill
Greenhorn

Joined: Feb 27, 2012
Posts: 29

"fix the applet so that if a user enters a radius and then presses Enter, the area text box will show the true area.

You also have a choice about the area text box. You can either make it so that if the user enters an area and presses Enter, the radius text box will show the new radius. Or, you can disable the area text box so data cannot be entered into it."
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18129
    
    8

That requirement says nothing about any numbers being different. All it says is that when the user presses Enter in the radius text box, then the corresponding area must be put into the area text box.

You already have code which is executed when the user presses Enter in the radius text box, don't you? So according to the requirements, that code should be calculating the corresponding area and putting it into the area text box, no? Your code doesn't quite do all of that yet.
Mack Grill
Greenhorn

Joined: Feb 27, 2012
Posts: 29

That's exactly what I have left to do but am not sure how to finish it.

I know that a method needs to be put into the if clause of tf1 but am not sure which method to use.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18129
    
    8

So your question turns out to be "How do I set the value of a TextField?"

Well, I haven't ever used one of those because AWT applets have been obsolete for a decade now. (And so has the practice of starting beginners out with applets, for that matter.) But anyway my guess is that TextField has a setText(String) method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to change area textbox when value is changed
 
Similar Threads
JTextfield
applet to applet communication
Help,Components inside my Frame would not be displayed until maximized.
Focussing a TextField
JDBC applets