Results 1 to 6 of 6
Thread: Applet won't start
- 07-13-2009, 07:38 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 3
- Rep Power
- 0
Applet won't start
Ok I am kinda new to java and I am trying to load an image and display it to the screen. It compiles without errors but it refuses to load the image.
Here is the code:
It just shows an empty screen without any errors.Java Code:import java.awt.Graphics; import java.awt.Image; public class MyPro extends java.applet.Applet { Image img; public void init() { img = getImage(getCodeBase(), "Mario.bmp"); } public void paint(Graphics g) { g.drawImage(img, 0, 0, this); } }
What am I doing wrong?
-
It's probably not finding the image. If it were my money, I'd use a Swing JApplet rather than an AWT Applet, and I'd read the Sun applet tutorial which I believe will show you you how to do this:
http://java.sun.com/docs/books/tutor...plet/data.htmlLast edited by Fubarable; 07-13-2009 at 07:49 PM.
- 07-13-2009, 09:22 PM #3
img = getImage(getCodeBase(), "Mario.bmp");
The getImage method will not read bmp images. Supported extensions are: gif, jpg and png.
ImageIO will read bmp and wbmp image formats in j2se 1.5+
Also, getImage returns immediately, ie, it doesn't block program execution to load the image data.
To load the image data you need the help of a MediaTracker — the api has sample code showing how to use it.
MediaTracker also has methods you can use to inquire about the success/failure of the loading process. No exceptions are thrown if the image file is not found or if the data in it is unreadable/corrupted so you have to ask.
This is another advantage of the newer ImageIO.read methods — they throw (IllegalArgument) exceptions to let you know if the data was not successfully loaded.
- 07-13-2009, 09:56 PM #4
Member
- Join Date
- Jul 2009
- Posts
- 3
- Rep Power
- 0
Thanks I just changed the extension to jpg and it works great. xDThe getImage method will not read bmp images. Supported extensions are: gif, jpg and png.
-
Hardwired -- the forum software won't let me "rep" you again, but thanks for catching the bmp issue.
- 07-14-2009, 05:32 AM #6
Member
- Join Date
- Jul 2009
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
How do you start a Java program from the "Start" menu under Windows?
By ScottVal in forum New To JavaReplies: 5Last Post: 03-20-2009, 10:04 PM -
[SOLVED] "start: applet not initialized"
By DenniGa in forum Java AppletsReplies: 3Last Post: 02-24-2009, 02:10 AM -
how to start a Web Java applet without a webbrowser
By racker79 in forum Java AppletsReplies: 3Last Post: 09-22-2008, 06:30 PM -
How to start
By sand.softnet1 in forum New To JavaReplies: 5Last Post: 09-05-2008, 07:41 PM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks