1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
public class PanelImage extends JPanel{
private ImageIcon img1;
private ImageIcon img2;
public PanelImage() {
//java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
//img1 = toolkit.getImage("feuille1.jpg"); //pour les types Image
img1 = new ImageIcon("feuille1.jpg");
img2 = new ImageIcon("feuille2.jpg");
Dimension dim=new Dimension(img1.getIconWidth(), img1.getIconHeight());
setSize(dim);
setPreferredSize(dim);
setMinimumSize(dim);
setMaximumSize(dim);
}
public int getIconHeight()
{
return 453;
}
public int getIconWidth()
{
return 320;
}
public void paintIcon(Component c, Graphics g, int x, int y )
{
this.getIconHeight();
this.getIconWidth();
}
//afficher les images
public void paint(Graphics g)
{
//tracer l'image originale
//g.drawImage(img1, 0, 0, this); // pour les types Image
//tracer l'icône
img1.paintIcon(this, g, 0, 0);
img2.paintIcon(this, g, 320, 0);
}
public static void main(String[] args) {
//Initialisation de la frame contenant l'applet
JFrame frame = new JFrame();
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = env.getMaximumWindowBounds();
frame.setBounds(bounds);
frame.setTitle("Test affichage d image");
//jpanel et jscrollpane
PanelImage pan = new PanelImage();
JScrollPane scroll = new JScrollPane(pan);
//frame.getContentPane().setLayout( new BorderLayout() );
frame.getContentPane().add(scroll, BorderLayout.CENTER );
frame.setVisible(true);
}
} |
Partager