// Acting on mouse movement - display mouse coordinates
// A second class - observe the constructor
import java.awt.*;         // for Panel, TextField
import java.awt.event.*;   // for MouseMotionListener
import javax.swing.*;
import java.applet.*;

class MousePad extends JPanel implements MouseMotionListener {

   JTextField mouse_x, mouse_y;
   
   MousePad (JTextField x, JTextField y) {

      mouse_x = x;
      mouse_y = y;

      mouse_x.setEditable(false);
      mouse_x.setBackground(Color.green);

      mouse_y.setEditable(false);
      mouse_y.setBackground(Color.yellow);

      setBackground(Color.blue);
      addMouseMotionListener(this);
   }
   
   public void mouseDragged (MouseEvent event) {
   }
   
   public void mouseMoved (MouseEvent event) {
      mouse_x.setText(String.valueOf(event.getX()));
      mouse_y.setText(String.valueOf(event.getY()));
   }
}

public class UsingMouse extends Applet {

   JTextField mouse_x, mouse_y;
   
   public void init() {

      setLayout(new BorderLayout());

      JPanel p = new JPanel();
      p.setLayout(new FlowLayout());
      p.add(new JLabel("x:",JLabel.RIGHT));
      p.add(mouse_x = new JTextField(6));
      p.add(new JLabel("y:",JLabel.RIGHT));      
      p.add(mouse_y = new JTextField(6));
      p.add(new JLabel(""));
      add("North", p);
      
      MousePad mp = new MousePad(mouse_x, mouse_y);
      add("Center",mp);
   }
}

