import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Square extends JApplet {
int size;
public void init()
{
String input = JOptionPane.showInputDialog(
"Enter square size:");

size = Integer.parseInt( input );
}
public void squareOfCharacters( Graphics g )
{
String input = JOptionPane.showInputDialog(
"Enter Character:");
int y = 50, x = 5;
for ( int a = 1; a <= size * size; a++ ) {
g.drawString( "\n%s!\n", x += 5, y );

}
}
public void paint( Graphics g )
{
squareOfCharacters( g );
}
}

I am having the worst time with this. I am supposed to form the square out of whatever character is contained in character parameter fillcharacter. Thus, if side is 5 and fillcharacter is"#", the method should display
#####
#####
#####
#####
#####

Thanks..............

First, you should take out the JOptionPane from teh squareOfCharacters method, otherwise you'll be prompted every time the applet repaints.

And instead of using a single FOR loop, use two nested FOR loops. The outer loop would be your row counter (up-down) and the inner loop would be your columns(left-right).

Rather than draw each individual characters of every line, build a string of the needed length (in this case 5) and then draw the string row once.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.