Anonymous: MouseMotionAdapter : MouseMotionAdapter « java.awt.event « Java by API






Anonymous: MouseMotionAdapter

import java.awt.Color;
import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainClass {

  public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(200, 200, 200, 200);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container content = aWindow.getContentPane();
    content.add(new MouseMotionAnonymous());
    aWindow.setVisible(true);
  }
}

class MouseMotionAnonymous extends JPanel {

  public MouseMotionAnonymous() {
    setBackground(Color.white);
    addMouseListener(new MouseAdapter() {
      public void mouseReleased(MouseEvent me) {
        setBackground(Color.white);
        repaint();
      }
    });
    addMouseMotionListener(new MouseMotionAdapter() {
      public void mouseDragged(MouseEvent me) {
        setBackground(Color.cyan);
        repaint();
      }
    });
  }
}
           
       








Related examples in the same category

1.extends MouseMotionAdapter