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
| import java.awt.*;
import java.awt.event.*;
import javax.swing.SwingUtilities;
public class Ex2 extends Canvas implements MouseListener{
public Point p=new Point();//classe Point dnc nécessairement il faur faire une instanciation
Frame f=new Frame();
Ex2(){
f.setSize(300,300);
this.addMouseListener(this);
f.add(this);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}//Fin constructeur
public void mouseClicked(MouseEvent e) {
p=e.getPoint();
}
public void mouseEntered(MouseEvent e) {
System.out.println("Début");
}
public void mouseExited(MouseEvent e) {
System.out.println("Fin");
}
public void mousePressed(MouseEvent e) {
System.out.println("vous appuyez sur le bouton");
}
public void mouseReleased(MouseEvent e) {
System.out.println("vous relachez le bouton ");
if(SwingUtilities.isLeftMouseButton(e))
repaint();
}
public void paint(Graphics g){
String chaine="(" +p.x+","+p.y+")";
g.drawString(chaine,p.x,p.y);
}
public static void main (String[] args ){
Ex2 t=new Ex2();
}
} |