Bonsoir,

j'utilse netbeans 5.0; je voudrais realiser l'appli suivante:

-1 clic droit dessine dans la fenetre un rond rouge
-1 clic gauche dessine un carre blanc
-lorsque la souris se déplace, la trajectoire qu'elle suit devra être déssinée en noire

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
/*
 * MonAppli.java
 *
 * Created on 21 septembre 2006, 15:56
 */
 
/**
 *
 * @author  cours uva
 */
 
import java.awt.*;
import javax.swing.*;
import java.awt.event.MouseEvent;
 
 
public class MonAppli extends javax.swing.JFrame {
 
    /** Creates new form MonAppli */
    public MonAppli() {
        initComponents();
    }
 
    public void paint(Graphics crayon)
 
  {  // code decrivant ce qu'il faut dessiner dans la fenetre
   // par exemple:
   crayon.setColor(Color.black); // selection de la couleur du crayon
   crayon.drawOval(50,50,100,200);  // trace un cercle
  }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(153, 153, 153));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
 
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 800, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 528, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>                        
 
    private void formMouseClicked(java.awt.event.MouseEvent evt) {                                  
// TODO add your handling code here:
/*int x = getX() ;
int Y = getY() ;
int etat = getButton() ;*/                 
    }                                 
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MonAppli().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    // End of variables declaration                      
}
Comme vous le constatez, ce n'est pas le résultat attendu: la fenetre s'affiche avec un cercle déjà déssiné à l'intérieur. Quelqu'un peut il m'aider?