Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Applet: Image loading/displaying help

Name: Anonymous 2009-02-13 22:47

Any Java programmers, help me. Java is driving me fucking nuts.

I'm trying to upload and display a picture in a java applet, and for some godforsaken reason, I can't get it to work. The code is as follows:

package TestImageLoad;
import java.awt.Graphics;
import java.awt.*;
import javax.swing.*;

public class TestImageLoad extends java.applet.Applet {
Image img;

public void init() {
resize(150,150);
img = getImage(getDocumentBase(), "Picture.bmp");
}

public void paint(Graphics g) {
g.drawString("Hello world!", 10, 25);
g.drawImage(img, 10, 40, null);
}
}

The "Hello World!" is displayed, so I know the paint function is called, but either the image is not loading or it's not displaying. The file "Picture.bmp" is located in both the source directory and the one above it (the one that has the .classpath and .project).  I'm using eclipse.

Good god, can someone help me with this.

Name: Anonymous 2009-02-13 22:54

Read SICP?

Name: Anonymous 2009-02-13 22:59

Buffer.

Name: Anonymous 2009-02-13 23:02

The problem isn't conceptual; I've done the same thing I'm trying to do here in other languages.  I'm fairly convinced the problem is syntactical, lying somewhere in my inability to understand exactly what the fuck java is doing in order to figure out why it's not doing what I'm asking.

Name: Anonymous 2009-02-13 23:08

I only have a vague understanding of what you mean by "buffer".  From what I understand this to mean, I think you are saying to verify (or allow) the image to be uploaded fully before displaying it.  But how to do this is beyond me.

Name: Anonymous 2009-02-13 23:11

Try compiling outside of Eclipse and see if it works.

Name: Anonymous 2009-02-14 2:00

Use a PNG instead of BMP

Name: Anonymous 2009-02-14 2:17

It's not ENTERPRISE enough.

Name: Anonymous 2009-02-14 7:36

public abstract Image getImage(String filename)
Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG

Name: Anonymous 2009-03-06 7:00


Code for a new   line so as   I type Unlimited!

Name: Anonymous 2011-02-02 23:51

Name: Anonymous 2011-02-04 14:59

Don't change these.
Name: Email:
Entire Thread Thread List