import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import javax.imageio.*;
public class GQ3 extends JFrame {
public GQ3() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.setBackground(Color.green);
contentPane.setLayout(new BorderLayout());
Test4Rx imagePanel = new Test4Rx("images/hawk.jpg");
contentPane.add(imagePanel, "North");
contentPane.add(new Test4Rx("images/bison.jpg"));
pack();
setLocationRelativeTo(null);
setVisible(true);
}
public static void main (String[] args) {
new GQ3();
}
}
class Test4Rx extends JComponent {
BufferedImage image;
int w,h;
public Test4Rx(String path) {
try {
image = ImageIO.read(new File(path));
w = image.getWidth();
h = image.getHeight();
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
System.exit(0);
}
}
public Dimension getPreferredSize() {
return new Dimension(w,h);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image,0,0,this);
}
public void main(String[] args) {
Test4Rx t = new Test4Rx("geo2.jpg");
JOptionPane.showMessageDialog(null, t, "", -1);
}
}