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
|
package hex;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JPanel;
/**
*
* @author Gabou
*/
public class Hexagone extends JPanel {
private int xHex[] = {0, 16, 32,32,16,0};
private int yHex[] = {10,0,10,30,40,30};
private int xHexInt[] = {1, 16, 31,31,16,1};
private int yHexInt[] = {10,1,10,30,39,30};
private Color couleur = Color.WHITE;
public Hexagone(){
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHints(hints);
g2d.drawPolygon(xHex, yHex, 6);
g2d.setColor(couleur);
g2d.fillPolygon(xHexInt, yHexInt, 6);
}
public Color getCouleur() {
return couleur;
}
public void setCouleur(Color couleur) {
this.couleur = couleur;
}
} |
Partager