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
|
class MyButton extends JButton
{
// attributs
private int taille;
private int x = 0;
private int y = 0;
private String pathImg;
private Toolkit toolkit = Toolkit.getDefaultToolkit();
// constructeur --> initialise juste les attributs du dessus
MyButton( int x, int y, int taille, String pathImg )
{
this.x = x;
this.y = y;
this.taille = taille;
this.pathImg = pathImg;
} // fin constructeur
// dessinateur
public void paintComponent(Graphics g)
{
Image i = redimentionner(toolkit.getImage(pathImg), taille);
setBounds(x, y, taille, taille);
g.drawImage(i, 0, 0, null);
} // fin paintComponent
// code du scale 'franciser' sur la FAQ... pas inportant
public static Image redimentionner( Image imageSrc, int widthHeight )
{
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bufferedImage.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(imageSrc, 0, 0, width, height, null);
g.dispose();
return bufferedImage;
}
} // fin class
/*
puis un main avec une frame.add(new MyButton(0, 0, 30, "C://personne.jpg"))
enfin, a pu pres...
*/ |
Partager