1 Replies - 554 Views - Last Post: 02 February 2011 - 08:31 PM Rate Topic: -----

#1 fallenreaper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Silly question about drawing a rectangle as mine isnt working

Posted 02 February 2011 - 08:23 PM

In my shape panel, i have the paintComponent method which is where i put my informationbut when the screen refeshes nothing goes on.

Below is paint component, and called methods, but on my screen nothing appears.. my Panel is just blank. Ideas on what i may be missing? I know for a fact that the code IS iterating through paintComponent

public void paintComponent (Graphics g){
			super.paintComponent(g);
			Graphics2D g2d = (Graphics2D) g;
			b.draw(g2d);
			pieces.draw(g2d);
			//redraw elements here.
		}

//code for the b.draw()
public void draw(Graphics2D g){
		for (int i = 0;i<8;i++){
			for(int j = 0; j < 8; j++){
				if (i%2 == 0){
					if(j%2 ==0){
						g.setColor(Color.BLACK);
						g.drawRect(i*cw, j*ch, w, h);
					}else{
						g.setColor(Color.YELLOW);
						g.drawRect(i*cw, j*ch, w, h);
					}
				}else{
					if(j%2 ==0){
						g.setColor(Color.YELLOW);
						g.drawRect(i*cw, j*ch, w, h);
					}else{
						g.setColor(Color.BLACK);
						g.drawRect(i*cw, j*ch, w, h);
					}
				}
			}
		}
	}


//code for pieces.draw()

public void draw(Graphics2D g){
		//g.setColor(color);
		//g.draw(piece);
		for(int i = 0; i< 8;i++){
			for(int j = 0; j < 8; j++){
				if(c[i][j] == 'B'){
					g.setColor(Color.BLUE);
				}else if (c[i][j] == 'W'){
					g.setColor(Color.WHITE);
				}else{//empty
					continue;
				}
				g.drawOval(b.getBlockWidth()*i+b.getBlockWidth()/2, j*b.getBlockHeight()+b.getBlockHeight()/2, b.getBlockWidth()/2, b.getBlockHeight()/2);
			}
		}
	}



Is This A Good Question/Topic? 0
  • +

Replies To: Silly question about drawing a rectangle as mine isnt working

#2 fallenreaper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: Silly question about drawing a rectangle as mine isnt working

Posted 02 February 2011 - 08:31 PM

just incase you didnt know. b.draw will draw a checker patterned board of colors black and yellow (same style worked with panels with background, but wanted to change it to rectangles.

The bottom, will iterate through an [][] of char's which will if see a 'B' draw a blue circle, and similarly with 'W' is white. getBlcokWidth returns the width of a square on the board so that i can make a circle fit correctly incase of resizing, similar with getBlockHeight..

cw and ch in the first method are the defined width/height of a square respectivally...

if you couldnt tell, they are implemented in different classes. ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1