【axelヘルプコード】単位正方形に穴を開けるために、ネット上でこのコードを取得しました.

3625 ワード

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.awt.geom.*;

import javax.swing.*;



public class getxy2

{

   public static void main(String[] args)

   {

      EventQueue.invokeLater(new Runnable()

         {

            public void run()

            {

               MouseFrame frame = new MouseFrame();

               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

               frame.setVisible(true);

            }

         });

   }

}



class MouseFrame extends JFrame

{

   public MouseFrame()

   {

      setTitle("MouseTest");

      setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);



      // add component to frame



      MouseComponent component = new MouseComponent();

      add(component);

   }



   public static final int DEFAULT_WIDTH = 500;

   public static final int DEFAULT_HEIGHT = 500;

}



class MouseComponent extends JComponent

{

   public MouseComponent()

   {

     

      addMouseListener(new MouseHandler());

      

   }

private class MouseHandler extends MouseAdapter

   {

      



      public void mouseClicked(MouseEvent event)

      {

        

         System.out.println(event.getPoint().getX()/500+" "

         +event.getPoint().getY()/500+" "+0.0);

         

   }

}

}