Bonjour,

J'espère que je suis au bon endroit pour poster mon problème que j'ai rencontré concernant le plateau hexagonal. La création d'une fenêtre est faite jusqu'à ce que je n'ai pas réussi. J'ai fait le code que je veux afficher la grille hexagonale dans JPanel, l'erreur n'est pas signalée mais la grille n'affiche pas. Je ne vois pas vraiment pourquoi je ne peux pas l'afficher.

Voici un bout de code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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);
		}
	}
}
J'ai hésité de faire une méthode getPolygon que getHex :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
	public  static Point getPolygon(Point center, double size, int cote){
		double angle_deg = 60 * cote  + 30;
		double angle_rad = Math.PI / 180 * angle_deg;
 
		return new Point(center.x + size * Math.cos(angle_rad), center.y + size * Math.sin(angle_rad));
 
	}
Si vous avez d'autres codes à me conseiller, je serai preneuse et merci !