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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| import javax.swing.JPanel;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Graphics2D;
import javax.swing.JScrollPane;
import java.awt.BasicStroke;
public class Panneau extends JPanel {
final static int cote=26;
private Image bg;
private static Point[][] hexSamplePoints;
int Col = 11;
int Ligne = 46;
Point hovered = null;
//Polygon pol;
int RR = 35;
int Oxx = 48;
int Oyy = 52;
int x[] = {0, 0, 0, 0, 0, 0};
int y[] = {0, 0, 0, 0, 0, 0};
public void paintComponent(Graphics g){
Tuile t = new Tuile(); => j'ai créé une classe pour charger une image
bg = t.chargerImage("map.jpg");
g.drawImage(bg,0,0,this);
BasicStroke bs=new BasicStroke(5);
super.paint(arg0);
Graphics2D g2d;
for(int i = 1; i < Ligne; i=i+2)
{
for(int j = 0; j < Col; j++)
{
Polygon poly = getHex(Oxx, Oyy, RR);
//Polygon poly = getPolygon(i, j);
}
g2d.draw(poly);
}
if(hovered!=null){
g.setColor(Color.red);
g2d.setStroke(bs);
Polygon p = getHex(Oxx, Oyy, RR);
//Polygon p=getPolygon(hovered.x, hovered.y,cote);
g2d.draw(p);
}
}
public static Point getHex(int Ox, int Oy, int R){
for (int j = 0; j < Ligne; j++){
for (int i = 0; i < Col; i++){
x[0] = Ox - R;
y[0] = Oy;
x[1] = Ox - R/2;
y[1] = Oy - R;
x[2] = Ox + R/2;
y[2] = Oy - R;
x[3] = Ox + R;
y[3] = Oy;
x[4] = Ox + R/2;
y[4] = Oy + R;
x[5] = Ox - R/2;
y[5] = Oy + R;
Ox = Ox + 3*R;
System.out.println("inc x : " + Ox);
g.drawPolygon(x, y, 6);
}
Oy = Oy + R;
if (Ox == Oox + R * 3 * Col){
Ox = Oox + R + R/2;
}
else {
Ox = Oox;
}
System.out.println("inc y : " + Oy);
}
}
} |
Partager