hi all
how can i draw rectangle for each graphic. on the picture, each rectangle is create as graphic. pls help.

You can draw a rectangle with a certain colored background, but you don't indicate what tools you're using, what platform or anything. Nor are you posting code that you attempted!

You can draw a rectangle with a certain colored background, but you don't indicate what tools you're using, what platform or anything. Nor are you posting code that you attempted!

well as u can see there i dun want rectangle with colored background, my em using Windows pltfrm.
i want to draw black rect. for each cell. i hav attech my code which create this graphic...

public void paint(Graphics g) {
			BufferedImage image = (BufferedImage) createImage(WIDTH, WIDTH);
			Graphics g2 = image.getGraphics();
			g2.setColor(Color.GRAY);
			g2.fillRect(0, 0, WIDTH, WIDTH);
			int n = (int) Math.sqrt(maze.length());
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					char type = maze.charAt(i + j * n);
					drawMazeArea(g2, i, j, n, type);

				}
			}
			g.drawImage(image, 0, 0, this);
		}

		void drawMazeArea(Graphics g, int i, int j, int n, char type) {
			if (type == 'O')
                             {
				g.setColor(Color.BLUE);

                             }
			if (type == 'P')
			{
				g.setColor(Color.WHITE);

			}
			if (type == 'S')
			{
			      g.setColor(Color.RED);

			}
                         if( type == '.')
                         {
				g.setColor(Color.RED);

                         }

			if (type == 'E')
			{
				g.setColor(Color.GREEN);

			}
			int r = WIDTH / (n + 3);
			int x = i * r + r, y = j * r + r, width = r, height = r;
			g.fillRect(x, y, width, height);
			g.setColor(Color.WHITE);
			if (type == 'S')
			{
                                 g.setColor(Color.WHITE);
				g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360);
                                 g.setColor(Color.BLACK);
                               g.fillArc(x + r / 3, y + r / 3, width / 3, height / 3, 0, 360);
                          }
			if (type == 'E')
                        {     g.setColor(Color.WHITE);
				g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360);
			 g.setColor(Color.RED);
                               g.fillArc(x + r / 3, y + r / 3, width / 3, height / 3, 0, 360);
                         }

		}

i want to make graphic like this

thank you.

You appear to be painting rectangles with filled foregrounds instead of filled backgrounds, which is fine. So what is really your problem. You are not clear as to what you need!

You can use case statements instead of those if conditionals. And for clarity, change WIDTH, WIDTH, to WIDTH, HEIGHT, even though WIDTH = HEIGHT. You do use a width, height in your code but you don't show their declarations.

i know i used width width for both width and hieght, as i told you i just want to draw rectangle srounding the each color cell thats all. thank u

If you are talking about a border around each cell, then just draw the square in position with spacing between each.

coordinates are:

Ex: wide = 10
border = 3
Outside border = 5
width = (wide * count) + (border * (count-1)) + (outside * 2)
height = width
x0 = 0
xy[0] = x0 + outside
xy[1] = xy[0] + wide + border
xy[2] = xy[1] + wide + border

you can stuff them in an array to get your x,y offset for each tile!
If you wanted, you could adjust them...

cx[0] = xy[0] + wide >> 1
cx[1] = xy[1] + wide >> 2
cx[2] = xy[2] + wide >> 3

for calculating the arc/circle centers. That way you merely lookup the coordinate and don't have to calculate it each time.

The built in offsets gives you your borders!
If you need a different colored edge then the game background then increase the rectangle size, paint your color, then repaint using the correct size. You now have a border.

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.