How to simpe use sprit istead of fillRect

Hi!
Im farly new to java , but i have managed to make my self a PONG game!:slight_smile: and it works! The ball is a graphics fillOval
and the pad is rect ( g.fillRect(x, 630, WIDTH, HEIGHT); ).

I have tried to use a sprite instead for the pad but cant seem to get it to work. I have a file called rect.png that i want to use as the pad.
I have all the move code ready so just need to load the image of the pad isted of the fillRect.

Anyone know how?

Can you please search google first?

g.drawImage(image, x, y, null);

As trollwarrior said, there are plenty of information on the subject. Google or search for some youtube tutorials so you get a bigger understanding of Bufferedimage and all that good stuff. :slight_smile:

public void paint(Graphics2D g) throws IOException{
URL url = this.getClass().getResource(“C:\bg\rect.png”);
BufferedImage img = ImageIO.read(url);
g.fillRect(x, 630, WIDTH, HEIGHT);
g.drawImage(img,x,630,null);
}

Getting errors…hmmm

Use code tags.

Made it work!:slight_smile:

BufferedImage img = ImageIO.read(new File(“C:\bg\rect.png”));

Dude, I am also new here.

But I never asked this kind of question.
Before you ask try to ask GOOGLE or YAHOO first.

and for more, you can check this site: http://zetcode.com/tutorials/javagamestutorial/
you can learn different stuffs there.

Ask question if you really can`t understand the use of this or that.
Or better. try to code then show it here and what is the problem.

Thanks.

P.S. I am also newbie.

Just make sure you are loading the image only once, outside of the paint method in some constructor or something :point:

But not YAHOO.
You might as well go into a public place and shout your question at strangers.
/joke

Is there any difference with YAHOO and GOOGLE?

I always search using YAHOO.

Um yeah there is. Yahoo is just plain bad to look at. Sure, you might get the same content, but Google has everything. YouTube, Android etc… why would I ever use Yahoo when I can integrate all my content under one account? Not to mention that Google’s search interface is by far the best to look at, there’s not clutter on the sides like all the other search engines.