Bonsoir à tous,
Voilà ça fait un moment que je planche sur un truc qui m'énerve !
J'ai une classe DrawArea qui étend JPanel, et sur laquelle je suis censée plus tard, dessiner des cercles.
Pour le moment, le problème qu'elle me pose, cette classe, c'est qu'elle ne veut pas s'afficher dans mon JPanel
C'est sûrement un truc tout bête mais là je sèche !
Pour info ma fenetre et mon panel de droite s'affichent sans problèmes.
Code de la classe DrawArea
Code java : 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 import java.awt.Color; import java.awt.FlowLayout; import java.awt.Graphics; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JLabel; public class DrawArea extends JPanel { private int xCoord; private int yCoord; private int height; private int width; public DrawArea(){ setBackground(Color.BLACK); add(new JLabel("test")); } /** pleins de getters/setters... */ public void paintComponent(Graphics g){ super.paintComponent(g); }
Et voici ma JFrame :
Code java : 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 import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class DrawingFrame extends JFrame { private DrawArea drawArea = new DrawArea(); public DrawingFrame(){ super("Drawing Ovals to your choice"); //set the size setSize(600,300); //creating a border layout for the config choices JPanel config = new JPanel (new BorderLayout() ); add(config, BorderLayout.LINE_END); /* Pleins de code entre deux qui concerne mon JPanel config */ //adding the drawing area getContentPane().add(drawArea, BorderLayout.LINE_START); drawArea.repaint(); } }
Partager