D:\840905170.doc
package ardoise;
import java.awt.*;
import javax.swing.*;
public class ardoise extends JFrame{
JPanel panDessin;
JLabel lbBarreEtat;
public ardoise() {
setTitle("Ardoise magique ");
setSize(new Dimension(300,180));
panDessin = new JPanel();
panDessin.setBackground(Color.white);
getContentPane().add(panDessin,BorderLayout.CENTER);
DessinListener listener = new DessinListener();
panDessin.addMouseMotionListener(listener);
lbBarreEtat = new JLabel();
lbBarreEtat.setText("Coordonnées du curseur : ");
getContentPane().add(lbBarreEtat,BorderLayout.SOUTH);
MajCoordonneesListener listenermaj = new MajCoordonneesListener(lbBarreEtat);
panDessin.addMouseMotionListener(listenermaj);
}
public static void main(String[] args) {
ardoise ar = new ardoise();
ar.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DessinListener implements MouseMotionListener {
public void mouseMoved(MouseEvent e) {
Graphics g = ((JComponent)e.getSource()).getGraphics();
g.drawRect(e.getX(),e.getY(),1,1);
}
public void mouseDragged(MouseEvent e) {
}
}
import java.awt.event.*;
import javax.swing.JLabel;
public class MajCoordonneesListener implements MouseMotionListener {
JLabel lbCible;
public MajCoordonneesListener(JLabel l) {
lbCible = l;
}
public void mouseMoved(MouseEvent e) {
lbCible.setText("Coordonnees du curseur :"+e.getX()+" ,"+e.getY());
}
public void mouseDragged(MouseEvent e) {
}
}