My applet is supposed to show a circle growing by asking the user for a beginning and ending radius (it's also supposed to check to make sure that r1 < r2, but I want to fix this part of code first.) My code throws tons of exceptions and asks the user for the radii twice, whether I use the console or JOptionPane (which is what I left it on.) I think it asks twice because of the thrown exceptions, but I really don't know, nor do I know how to fix these exceptions. The book I'm using is Java 6 Illuminated. Any ideas on how I should fix this? Thank you. :)
import javax.swing.JOptionPane;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JApplet;
public class BallGrows extends JApplet
{
public void paint(Graphics g)
{
super.paint(g);
final int X = 250;
final int Y = 250;
final Color COLOR = Color.BLUE;
String rad1 = JOptionPane.showInputDialog(null, "Beginning radius:");
String rad2 = JOptionPane.showInputDialog(null, "Ending radius:");
int r1 = Integer.parseInt(rad1);
int r2 = Integer.parseInt(rad2);
for(int i = r1; i <= r2; i++)
{
g.setColor(COLOR);
g.fillOval(X - i, Y - i, i*2, i*2);
}
}
}B