1 réponse
import javax.swing.*;
import java.awt.*;
public class TestImageIcon extends JFrame
{
// Images de drapeaux
private ImageIcon usIcon = new ImageIcon("image/us.gif");
private ImageIcon myIcon = new ImageIcon("image/my.gif");
private ImageIcon frIcon = new ImageIcon("image/fr.gif");
private ImageIcon ukIcon = new ImageIcon("image/uk.gif");
public TestImageIcon()
{
setLayout(new GridLayout(1, 4, 5, 5));
// Deux simples labels
add(new JLabel(usIcon));
add(new JLabel(myIcon));
// Deux boutons avec images dedans
add(new JButton(frIcon));
add(new JButton(ukIcon));
}
/** Main method */
public static void main(String[] args)
{
TestImageIcon frame = new TestImageIcon();
frame.setTitle("TestImageIcon");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
N'oublie pas de mettre les images us.gif, my.jpg, fr.gif, uk.gif dans un dossier "image". (petites images de préférence ^^)