I am trying to create a 2D array of Rectangles, and that works fine, however what wont work is when i try to set a dimension for one of the Rectangles in the array and draw it. My code is:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.Graphics2D;
public class DrawingPanel extends JPanel
{
Graphics2D MyG;
Rectangle[][] rect = new Rectangle[3][3];
DrawingPanel ()
{
setBackground (Color.WHITE);
}
public void paint(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.BLACK);
update(g);
}
public void update(Graphics g)
{
}
}
However when i try something like
rect[0][0] = new Rectangle (0,0,25,25);it gives me an error. And even when i try
Rectangle r1 = new Rectangle (0,0,25,25); rect[0][0] = r1;
it gives me an error about 'expecting a ]'
Any advice?
x5

New Topic/Question
Reply



MultiQuote



|