Forum Stats

  • 3,851,383 Users
  • 2,263,969 Discussions
  • 7,904,691 Comments

Discussions

Help

843807
843807 Member Posts: 46,582
edited Sep 27, 2002 2:03PM in Java Applet Development
Can someone tell me why I'm getting an error that says:

Assignment5.java [52:1] 'void' type not allowed here
Pointing to the line below.
g.drawString( squareOfAsterisks(choice), 20, 40);

I know the output isn't going to come out the way I want it to, but I should get 1 '*' to print. Am I calling my function wrong??

Code below:
//Java core packages
import java.awt.*;
//Java extension packages
import javax.swing.*;

public class Assignment5 extends JApplet
{
String input;
int i;
int j;
int choice;


//initialize applet by obtaining user's choice
public void init()
{
//obtain user's choice
input = JOptionPane.showInputDialog(
"This program with draw a square with asterisks (*)\n" +
"dependant upon the input you enter. For example,\n" +
"enter a 3, the result will look like: \n" +
" ***\n" +
" ***\n" +
" ***\n" +
"Please enter how large you want the square of asterisks\n" +
"to be\n\n");

//convert type String to integer named choice
choice = Integer.parseInt( input );
}

public void paint( Graphics g )
{
g.drawString( "Your output is: ", 20, 20);
g.drawString( squareOfAsterisks(choice), 20, 40);

}

public void squareOfAsterisks(int choice)
{
for (i = 1; i <= choice; i++)
{
for (j = 1; j <= choice; j++)
{
System.out.print("*");
}
System.out.println ("\n");
}

}
}

Comments

This discussion has been closed.