K , im trying make a program were when u enter a number it draws a circle. The number entered is the radius (width) of the circle. "yes i know its stupid but im just messing around " > Now my problem is that if u enter a something either than a number its craps out , wondering if anyone can help nme out on this. Heres my code , its does not compile due to a few errors . Appreciate any help giving.
import java.applet.*;
import java.awt.*;
public class Circle_drawing_GUI extends Applet
{
Label diameter;// , heightof ;
TextField diameter_input;// , height_input ;
int x , y ;
String width ; //;, height;
public void init ()
{
diameter = new Label ("Enter radius");
diameter_input = new TextField (5);
//heightof = new Label ("Enter height");
// height_input = new TextField (5);
add (diameter);///aaa
add (diameter_input);
// add (heightof);
// add (height_input);
}
public boolean action (Event e , Object o)
{
Graphics g = getGraphics() ;
width = diameter_input.getText();
//height =Integer.parseInt (height_input.getText());
x = Integer.parseInt (catch_method(""));
g.drawOval (getSize ().width / 2 , getSize().height / 2 , x , 50);
return true ;
}
static public String catch_method (String input) // reads string input that cannot be transferred to integer
{
int valid ;
while (true)
{
try
{
valid = Integer.parseInt (width);
break;
}
catch (NumberFormatException e)
{
showStatus ("invalid input") ;
}
} // while
return valid.toString();
} //closing catch_method
}