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
Comments
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);
}
}
}
class Pause
{
static void wait(double seconds){}
}
This code eliminates the double prompts.
[code]
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class BallGrows extends JApplet {
String rad1, rad2;
public void start() {
getInput();
}
public void getInput() {
rad1 = JOptionPane.showInputDialog(null, "Beginning radius:");
rad2 = JOptionPane.showInputDialog(null, "Ending radius:");
}
public void paint(Graphics g) {
super.paint(g);
final int X = 250;
final int Y = 250;
final Color COLOR = Color.BLUE;
int r1 = 25; // default values
int r2 = 25; // default values
if (rad1 != null) {
r1 = Integer.parseInt(rad1);
}
if (rad2 != null) {
r2 = Integer.parseInt(rad2);
}
g.setColor(COLOR);
for (int i = r1; i <= r2; i++) {
g.fillOval(X - i, Y - i, i * 2, i * 2);
g.drawOval(X - i, Y - i, i * 2, i * 2); // missing statement
}
}
}[/code]
The java virtual machine will invoke the paint() routine whenever it thinks it needs to be done. Thus the frequent input prompts.
regards, se52