How can I display a bitmap image in a Java applet? -
I have a hard time showing an image (or image icon) in the Java applet. .bmp) is present and on D drive but when I run it, there is no applet window in it. Can anyone tell me what is missing to create an immaculate show?
Public category Form 1 Jopplet {ImageIcon i; Public zero init () {i = new imagen ("d: \ test.bmp"); } Public Zero Color (Graphics G) {iPad Icon (It, G, 0, 0); }}
Thank you, Steve.
A full local file path referenced through your image will not work when you access your applet from the server Use the ImageIcon (URL location) manufacturer and point to image processing on the url server. Use JApplet.getCodeBase () to determine how your applet adds a file name and adds it.
Public class form 1 japplett {image i; Public zero init (try {i = imageIO.read (new URL (getCodeBase ("test.bmp")); } Grip (malarmudural lexception ex) {ex.printStackTrace (); } Hold (IOException pre) {ex.printStackTrace (); }} Public Zero Color (Graphics G) {g.drawImage (i, 0, 0, null); }}
Edit: ImageIO supports BMP and the converted sample works for me.
Edit 2: If it still does not display the image, then try "../test.bmp" because when you run an applet, say eclipse As a codebase, there is a bin
directory.
Edit 3: If you put your test. BMP in a jar or a classpath, you can load it in the same way but
GetCodeBase (), "test.bmp") withnew URL
form1.class.getResource ("test.bmp")
Comments
Post a Comment