Puoi usare il metodo drawImage della classe Graphics (all'interno di un metodo paint() ).
Questo è il prototipo:
codice:
g.drawImage(Image img, int x, int y, int width, int height, ImageObserver imgObs);
Ad esempio, puoi usare questa classe:
codice:
class Immagine extends JPanel {
private Image img;
private int width;
private int height;
public Immagine(Image img, int width, int height) {
this.img = img;
this.width = width;
this.height = height;
repaint();
}
public void paint(Graphics g) {
g.drawImage(img, 0, 0, width, height, this);
}
}
Puoi costruire un oggetto di questa classe nel modo seguente ed aggiungerlo alla finestra di visualizzazione:
codice:
...
Image img = Toolkit.getDefaultToolkit().createImage("nomefile");
Immagine miaImg = new Immagine(miaImg, dimLarghezza, dimAltezza);
...
add(miaImg);
Ciao.