Salut!
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* Created on 14-avr.-07
*
* @author: HackTrack
*/
public class DemoButton extends JButton {
private Color color;
private int rectWidth;
private int rectHeight;
private int offsetX;
private int offsetY;
public DemoButton(String text, Color color, int offsetX, int offsetY,int rectWidth, int rectHeight) {
super(text);
this.color = color;
this.rectWidth = rectWidth;
this.rectHeight = rectHeight;
this.offsetX = offsetX;
this.offsetY = offsetY;
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(color);
g.fillRect(offsetX, offsetY, rectWidth + offsetX, rectHeight+offsetY);
g.setColor(Color.WHITE);
g.drawRect(offsetX, offsetY, rectWidth + offsetX, rectHeight+offsetY);
//Ajoute ici tout ce que tu veux dessiner sur ton objet Graphics
}
public static void main(String[] args) {
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().add(new DemoButton("Play", Color.BLUE, 4, 4,20, 10));
jf.pack();
jf.setVisible(true);
}
}
;-)
HackTrack