【axel帮助代码】为了在单位正方形里面画一个洞 ,网上获取了此代码。

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);

         

   }

}

}

 

你可能感兴趣的:(代码)