The output of the code at the moment is the rectangle design and the first line of the array repeated. The wanted output is the rectangle design and the whole array rather than just the first line.
public class design
{
public static void main (String[] args)
{
JFrame window = new JFrame ("Game Screen");
window.getContentPane ().add (new drawing ());
window.setSize (500, 500);
window.setVisible (true);
window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
}
class drawing extends JComponent
{
public void paint (Graphics g)
{
int[] [] word = {{5, 3, 0, 0, 7, 0, 0, 0, 0},
{6, 0, 0, 1, 9, 5, 0, 0, 0},
{0, 9, 8, 0, 0, 0, 0, 6, 0},
{8, 0, 0, 0, 6, 0, 0, 0, 3},
{4, 0, 0, 8, 0, 3, 0, 0, 1},
{7, 0, 0, 0, 2, 0, 0, 0, 6},
{0, 6, 0, 0, 0, 0, 2, 8, 0},
{0, 0, 0, 4, 1, 9, 0, 0, 5},
{0, 0, 0, 0, 9, 0, 0, 7, 9}};
int r = 0;
int c = 0;
Graphics2D g2 = (Graphics2D) g;
Rectangle rect;
for (int x = 5 ; x < 450 ; x += 50)
{
for (int y = 5 ; y < 450 ; y += 50)
{
rect = new Rectangle (x, y, 50, 50);
g2.draw (rect);
g.drawString (Integer.toString (word [r] [c]), x + 25, y + 25);
}
c++;
if (c == 9)
{
c = 0;
r++;
}
}
rect = new Rectangle (150, 5, 150, 450);
g2.draw (rect);
rect = new Rectangle (5, 150, 450, 150);
g2.draw (rect);
}
}