Chargement d'une
image
depuis une application
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2001 */
import java.awt.*;
public class FichierImage {
public static void main(String [] args) {
MyFrame f = new MyFrame("Piece.gif");
f.setSize(100,100);
f.show();
}
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2001 */
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends Frame implements WindowListener {
private Toolkit t;
private Image i;
public MyFrame() {
super();
t = getToolkit();
i = t.getImage("Piece.jpg");
addWindowListener(this);
}
public MyFrame(String s) {
super(s);
t = getToolkit();
i = t.getImage("Piece.jpg");
addWindowListener(this);
}
public void paint(Graphics g) {
if ( i.getWidth(this) != -1 ) {
g.drawImage(i,0,0,this);
setSize(i.getWidth(this),i.getHeight(this)); }
}
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
}