Bonjour,
en realité je veut afficher plusieurs cercles mais je sais pas, le code affiche seulement le derneir,
code :et l'utilisation :
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 public class Sommet extends JPanel { private String desc; private int x; private int y; Sommet(String desc,int x,int y) { this.desc=desc; this.x=x; this.y=y; } public void paintComponent(Graphics g){ g.setColor(Color.red); g.fillOval(this.x, this.y, 75, 75); g.setColor(Color.WHITE); g.drawString(desc, x+27, y+40); } }
merci de m'aider
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 public class Tester { public static void main(String[] args) { JFrame f=new JFrame(); f.setTitle("Sommet"); f.setSize(900, 700); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Sommet s1=new Sommet("S2",100, 55); Sommet s2=new Sommet("S3",200, 95); f.getContentPane().add(s1); f.getContentPane().add(s2); f.setVisible(true); } }
Partager