import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class Fenetre extends Frame {
private Applet appletCourante;
class WAction extends WindowAdapter {
public void windowClosing(WindowEvent e) {
appletCourante.stop(); appletCourante.destroy();
((Window)e.getSource()).dispose();
}
}
Fenetre(Applet a,String titre, int l, int h) {
super(titre);
setSize(l, h);
addWindowListener(new WAction());
appletCourante = a;
add(a, BorderLayout.CENTER);
a.init();
show();
a.start();
}
}
class Dessin extends Applet {
int x0 = 0;
int y0 = 0;
TextArea t;
class MSouris extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
Graphics g = getGraphics();
g.drawLine(x0, y0, e.getX(), e.getY());
t.append("\n("+x0+","+y0+")->("+e.getX()+","+e.getY()+")");
x0 = e.getX(); y0 = e.getY();
}
}
class CSouris extends MouseAdapter {
public void mousePressed(MouseEvent e) {
x0 = e.getX(); y0 = e.getY();
}
}
public void init() {
t = new TextArea("(x, y)", 5, 20);
this.add(t);
addMouseListener(new CSouris());
addMouseMotionListener(new MSouris());
}
}
public class Interaction {
public static void main(String args[]) {
Fenetre f1 = new Fenetre(new Dessin(), "f1", 100, 200);
Fenetre f2 = new Fenetre(new Dessin(), "f2", 200, 250);
}
}