Results 1 to 4 of 4
- 11-30-2011, 01:52 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 28
- Rep Power
- 0
Loading an image and then using it as a background
Hey all so I am attempting to load an image and use it as a background for a 2d game I've made for my Java course. Here is what I have, and it is not working. No image is being loaded/displayed
Java Code:img = Toolkit.getDefaultToolkit().getImage(getClass().getResource("mario.jpg"));I don't see what the issue is here, but then again I dont have much experience in writing graphics. Thanks in advance!Java Code:public void drawBackground(Graphics graphics) { graphics.drawImage(img, 0, 0, this); }
- 11-30-2011, 01:54 PM #2
Member
- Join Date
- Nov 2011
- Location
- Schijndel, Netherlands
- Posts
- 12
- Rep Power
- 0
Re: Loading an image and then using it as a background
Try repaint().
- 11-30-2011, 04:00 PM #3
Re: Loading an image and then using it as a background
Irrelevant without associated advice on how to perform custom painting correctly.
Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-
Re: Loading an image and then using it as a background
You don't draw images like that, but rather than us re-write a chapter, your best bet is to find the graphics tutorials and read them before trying to do this stuff.
Similar Threads
-
use image for background
By tony_stark in forum AWT / SwingReplies: 1Last Post: 05-31-2011, 08:20 PM -
Java Applet loading image; render as you get image?
By ea25 in forum New To JavaReplies: 12Last Post: 04-14-2011, 01:58 PM -
[Help] W/ background image
By gundum584 in forum New To JavaReplies: 9Last Post: 01-10-2011, 05:48 AM -
Loading an image into JDesktopPane as background
By Rose88 in forum Advanced JavaReplies: 13Last Post: 08-25-2009, 01:10 AM -
Background image
By leiferouis in forum New To JavaReplies: 9Last Post: 03-08-2009, 05:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks