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.
class ImagePanel extends JPanel {
protected BuferedImage bi = null;
public ImagePanel(x,y,w,h) {
super();
this.setLocation(x,y);
this.setSize(w,h);
this.setLayout(new BorderLayout());
}
public boolean loadImage(String s) {
try {
File f = new File(s);
if(f.exists()) {
bi = ImageIO.read(f);
return true;
}
}
catch(Exception e) { }
return false;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(this.bi != null) {
g.drawImage(bi, this.getX(), this.getY(), this.getWidth(), this.getHeight(), null);
this.repaint();
}
}
}
Wrote this some time ago but never did more than compile it, not even used it once; this should give you the basic idea, though. Add it to a JFrame and play around.