Bonjour,

J'ai un programme avec un JFrame qui contient 3 JPanel.
Le probleme est que lorsque je veux dessiner dans un des JPanel(qui se trouve dans une autre classe, le getX(), me donne bien la taille du JPanel, mais le drawLine(x,y,x2,y2) concerne le x du JFrame et non du JPanel ce qui fait que je m'en sors pas.
Je ne parviens pas a récupérer la vrai taille du JFrame.

Je vous mets le code, si vous trouvez quelques choses ( ou si ma méthode est absolument pas a faire....)

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
 
 
 
public class MaFenetre extends JFrame{
	public static String title="mon titre";
	public int fenetreWidth = 700;
	public int fenetreHeight = 550;
 
	public static Dimension size = new Dimension (700,550);
 
	public PanneauBuild panneauBuild = new PanneauBuild();
	public PanneauJeu panneauJeu = new PanneauJeu();
	public PanneauScore panneauScore = new PanneauScore();
 
 
 
	public MaFenetre() {
		this.setTitle(title);
		this.setSize(size);
		this.setBackground(Color.white);
		this.setResizable(true);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
 
		//panneauBuild.setBounds(0, 0, (this.getWidth()/8), this.getHeight());
		//panneauScore.setBounds(this.getWidth()/8,0,(this.getWidth()-this.getWidth()/8),this.getHeight()/8);
		//panneauJeu.setBounds(this.getWidth()/8, this.getHeight()/8, (this.getWidth()-this.getWidth()/8), (this.getHeight()-this.getHeight()/8));
 
 
 
 
		init();
 
	}
	public void init() {
		while(true) {
		//placement des différents panneau + rafraichissement
		if ((this.getWidth() != fenetreWidth) || (this.getHeight() != fenetreHeight)) { //pour changement grandeur fenetre 
			fenetreWidth = this.getWidth();
			fenetreHeight = this.getHeight();
			panneauBuild.setBounds(0, 0, (this.getWidth()/8), this.getHeight());
			panneauScore.setBounds(this.getWidth()/8,0,(this.getWidth()-this.getWidth()/8),this.getHeight()/8);
			panneauJeu.setBounds(this.getWidth()/8, this.getHeight()/8, (this.getWidth()-this.getWidth()/8), (this.getHeight()-this.getHeight()/8));
			System.out.println("fenetre " + this.getWidth());
 
			this.getContentPane().add(panneauBuild);
			this.getContentPane().add(panneauScore);
			this.getContentPane().add(panneauJeu);}
 
 
			//panneauJeu.repaint();
			this.setVisible(true);
 
		panneauJeu.repaint();
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
 
 
		//screen.setBackground(Color.blue);
		//this.add(screen);
 
		}
 
	}	
 
 
 
 
	public static void main(String args[]) {
		MaFenetre frame = new MaFenetre();
 
	}
 
}
Et un des JPanel appellé sur lequel jessaye de dessiner

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
 
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
 
import javax.swing.*;
 
 
public class PanneauJeu extends JPanel {
 
	public int mycpt=0;
	public Block[][] block;
	public int jeuWidth;
	public int jeuHeight;
	public int widthAffichable;
	public int heightAffichable;
	public int margin = 50;
 
 
 
	//A changer taille du plateau jeu
	Screen screen = new Screen();
 
 
	public PanneauJeu() {
		block = new Block[screen.tailleMonde][screen.tailleMonde];
		setBackground(Color.green);
 
	}
 
 
	public void paintComponent(Graphics g) {
		//ecrase par un dessin
		g.setColor(Color.white);
		g.drawRect(0, 0, getWidth(), getHeight());
 
 
		jeuWidth = this.getWidth();
		jeuHeight = this.getHeight();
 
		widthAffichable = (int)Math.floor((jeuWidth-margin)/32);
		heightAffichable = (int)Math.floor((jeuHeight-margin)/32);
		g.setColor(Color.blue);
 
		//dessin de grille
		for (int i=0;i<=widthAffichable;i++) {
			g.drawLine(jeuWidth - (widthAffichable*32), margin+(i*32), (widthAffichable*32) - margin, margin + (i*32));
		}
		for (int i=0;i<=heightAffichable;i++) {
			g.drawLine(margin+(i*32), margin, margin + (i*32), (heightAffichable*32) -margin);
		}
 
	}
}
Merci de votre aide.