import java.awt.Image;
import java.awt.Graphics;
public class bild extends java.applet.Applet {
Image einBild;
// Bild wird geladen und an Grösse angepasst
public void init() {
einBild = getImage(getDocumentBase(), "bild.jpg");
}
// Bild wird ausgegeben
public void paint (Graphics g) {
// Bild definieren
g.drawImage(einBild, 0, 0, 500, 315, this);
}
}
Image image = null;
try {
// Read from a file
File file = new File("image.gif");
image = ImageIO.read(file);
// Read from an input stream
InputStream is = new BufferedInputStream(new FileInputStream("image.gif"));
image = ImageIO.read(is);
// Read from a URL
URL url = new URL("http://hostname.com/image.gif");
image = ImageIO.read(url);
}
catch (IOException e) {
}
// Use a label to display the image
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);