Page 902 - 3-2
P. 902
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Sedong frame = new Sedong();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Sedong() {
icon = new ImageIcon("/home/pi/048d2424.jpg");
//Dimension res = Toolkit.getDefaultToolkit().getScreenSize();
//setBounds(0,0,(int)res.width,(int)res.height);
contentPane = new JPanel(){
public void paintComponent(Graphics g) {
// Approach 1: Dispaly image at at full size
//g.drawImage(icon.getImage(), 0, 0, null);
// Approach 2: Scale image to size of component
Dimension d = getSize();
g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
// Approach 3: Fix the image position in the scroll pane
//Point p = contentPane.getViewport().getViewPosition();
// g.drawImage(icon.getImage(), p.x, p.y, null);
setOpaque(false);
super.paintComponent(g);
}
};
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new GridLayout(0, 2, 10, 10));
contentPane.setBackground(Color.WHITE);
- 902 -