Bonjour groupe. Je travaille avec NetBeans et j'aimerais afficher un cercle noir (50 pixels x 50 pixels) sur une carte géographique en cliquant sur le bouton #1 (voir exemple ci-dessous).

Nom : exemple1.jpg
Affichages : 999
Taille : 116,2 Ko

J'ai trouvé plein du tuto qui me fait apparaître mon cercle partout et je comprend le fonctionnement. Malheureusement, pas capable d'afficher un cercle dans ma fenêtre. Voici mon 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
99
100
101
102
 
 
import java.awt.*;
import javax.swing.*;
 
public class fenetre extends javax.swing.JFrame {
 
    public fenetre() {
        initComponents();
 
    }
 
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Insérer un cercle");
        setPreferredSize(new java.awt.Dimension(1148, 768));
        setResizable(false);
        setSize(new java.awt.Dimension(0, 0));
        getContentPane().setLayout(null);
 
        jButton1.setText("Afficher la ville #1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(920, 20, 200, 60);
 
        jButton2.setText("Afficher cercle #2");
        getContentPane().add(jButton2);
        jButton2.setBounds(920, 100, 200, 60);
 
        jButton3.setText("Afficher cercle #3");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton3);
        jButton3.setBounds(920, 180, 200, 60);
 
        jLabel1.setIcon(new javax.swing.ImageIcon("P:\\Essm_Codage_prof\\Travaux\\Stéphan\\comptearebours\\insertCercle\\src\\images\\canada56.gif")); // NOI18N
        jLabel1.setText("jLabel1");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, -180, 1140, 920);
 
        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>                        
 
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        
 
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        
 
 
    public static void main(String args[]) {
 
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
 
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new fenetre().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration                   
}

Où mettre ce 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
 
class Cercle 
{ 
   Point centre; 
   int rayon; 
 
   Cercle(int x, int y, int r) 
   { 
        centre = new Point(200,200); 
        rayon = 25; 
   } 
 
   void dessiner(Graphics g) 
  1 
  { 
        g.drawOval(centre.x - rayon, centre.y - rayon, 2*rayon, 2*rayon); 
  } 
}
Merci