Java
Home

Exemplo de MouseAdapter

 

/*
* Main.java
*
* Created on 20 de Fevereiro de 2007, 19:30
*/

package mouse_adapter;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

/**
*
* @author adrw
*/

public class Main extends JFrame {

   private int xValue = -10;
   private int yValue = -10;


   public Main() {
      super("Mouse test painter");

      addMouseMotionListener (

      new MouseMotionAdapter()
      {
         public void mouseDragged( MouseEvent event )
         {
            xValue = event.getX();
            yValue = event.getY();
            repaint();
         }
      }

      );

      setSize(300, 150);
      setVisible( true );
   }

   public void paint( Graphics g )
   {
      g.fillOval( xValue, yValue, 4, 4 );
   }

   /**
   * @param args the command line arguments
   */
   public static void main(String[] args)
   {
      Main app = new Main();
   
      app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
   }

}