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

Simplest way to draw images in Java

Name: Anonymous 2010-06-14 13:38

JFrame, ImageIO, Graphics2D, ImageBuffer... uhg
Lurking around I found there are a lot of complicated ways to do a simple thing.
So how does /prog/ throw up an image in java?
The fewest lines gets to name my first born.

Name: Anonymous 2010-06-14 14:36

Most ways are equivalently simple.  If I'm doing a throw away program with java that uses graphics, I make an applet to avoid the boilerplate of making a window.

import java.awt.*;
import java.applet.*;
public class a extends Applet{
    Image img;
    public void init(){
      img=getImage(getCodeBase(),"10x.JPG");
    }
    public void paint(Graphics g){       
        g.drawImage(img,0,0,null);       
    }
}

Note that because getImage is non-blocking, the image may not be loaded in time for the initial painting, use a blocking version like ImageIO.read() if this is an issue.

Don't mind the trolls, those that know how to program use languages that need 3rd party libraries to display an image.  Savages.

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