Jump to content

Problem with paint

- - - - -

  • Please log in to reply
3 replies to this topic

#1
zapdude1234

zapdude1234

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
This is probably a very simple problem but i was messing with some tile sheets and for some reason it isnt drawing any of the tiles out. any idea?
public void paint(Graphics g){

		super.paint(g);

		g.setColor(Color.BLACK);

		g.fillRect(0, 0, 300, 400);

		for(int x = 0; x < 10; x++){

			for(int y = 0; y < 10; y++){

				rect = new Rectangle(getSourceRectangle(getTileIndex(x,y)));

				try{

					Tile = createImage(new FilteredImageSource(TileMap.getSource(), new CropImageFilter(rect.x,rect.y,rect.width,rect.height)));

				}catch(Exception e){}

				g.drawImage(Tile,x*TileSize,y*TileSize,this);

			}

		}

		Toolkit.getDefaultToolkit().sync();

		g.dispose();

	}


#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Are you drawing onto a JPanel? an Applet? A Window?

#3
zapdude1234

zapdude1234

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
a JPanel. this is in a class with an extension of JPanel thats added to another JFrame class

#4
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
I recommend adding your painting code inside of the paintComponent(Graphics g) method instead of paint(Graphics g).
Are you manually doing the repainting?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users