Video and Audio

Storyboard

>Model

ID:(103, 0)



Strawberry Demo

Image

>Top


ID:(2436, 0)



Duke Java Symbol

Image

>Top


ID:(2438, 0)



Messy Image of Duke

Image

>Top


ID:(2437, 0)



Displaying the Image

Description

>Top


ID:(1244, 0)



How to protect the program errors?

Description

>Top


ID:(1243, 0)



Ejemplo Cargar Imagen

Description

>Top


El siguiente ejemplo carga y muestra una imagen desde un archivo:

```

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

import java.io.*;

import javax.imageio.*;

import javax.swing.*;

public class LoadImageApp extends Component {

BufferedImage img;

public void paint(Graphics g) {

g.drawImage(img, 0, 0, null);

}

public LoadImageApp() {

try {

img = ImageIO.read(new File("strawberry.jpg"));

} catch (IOException e) {

}

}

public Dimension getPreferredSize() {

if (img == null) {

return new Dimension(100,100);

} else {

return new Dimension(img.getWidth(null), img.getHeight(null));

}

}

public static void main(String[] args) {

JFrame f = new JFrame("Load Image Sample");

f.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

f.add(new LoadImageApp());

f.pack();

f.setVisible(true);

}

}

```

ID:(8828, 0)