My question deals with an example taht I am trying to attempt from a book. I would liek to have some help or guidance in solving this problem.
Write an
applet that reads in the size of the side of a square and displays a hollow square of that sizw out of asterisks, by using the drawString method inside your applets paint method. Use an input dialog to read the size from the user. Your program should work for squares of all lengths of side between 1 and 20.
Here is how I attemped this problem thus far.
import java.awt.Graphics;
import javax.swing.*;
public class Ch4_23 extends JApplet
{
int number1;
int number2;
int number3;
int number4;
int number5;
double modulus;
double sum;
public void init()
{
String firstNumber;
String secondNumber;
String thirdNumber;
String fourthNumber;
firstNumber = JOptionPane.showInputDialog(" Enter the first floating pont number");
secondNumber = JOptionPane.showInputDialog(" Enter the second floating point number");
thirdNumber = JOptionPane.showInputDialog(" Enter the first floating pont number");
fourthNumber = JOptionPane.showInputDialog(" Enter the second floating point number");
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
number3 = Integer.parseInt( thirdNumber );
number4 = Integer.parseInt( fourthNumber );
sum = number1 % number2;
}
public void paint( Graphics g)
{
super.paint( g );
g.drawRect( number1, number2, number3, number4);
number3 = number2 + 10;
number4 = number2 + 20;
number5 = number2 + 30;
g.drawString("***", number1, number2 );
g.drawString("* *", number1, number3 );
g.drawString("***", number1, number4 );
}
}
This isn't really getting the square highlighted with asterisks. It is however off when I attempt this. Can someone please guide me to figuring this one out?