3 Replies Latest reply: Aug 17, 2010 1:19 PM by 843807 RSS

    Window applet and mouse pointer

    843807
      Hi all!

      I am developing a framwork to create educacional games to the OLPC (one laptop per child) project.

      So, in this framework the games run in a Window application (JFrame) over a JApplet.


      The problem is that I dont know how to hide the mouse pointer that appears over my window applet. I try to use the Toolkit.createCustomCursor(..) and them use the setCursor(..) method, but not work because the security policy.


      Anybody have some ideia about how can I solve this problem?

      here is a link that demonstrate my application running, and the mouse pointer over all the graphics.

      http://nti.catolica-to.edu.br/Imagens/screenucamouse.png


      Thank you!
        • 1. Re: Window applet and mouse pointer
          800025
          What happens? Is some SecurityException thrown? And what exactly do you mean with
          the games run in a Window application (JFrame) over a JApplet.
          As far as I know, but I may be wrong, the following code should just runs fine:
          import java.awt.Point;
          import java.awt.Toolkit;
          import java.awt.image.BufferedImage;
          
          import javax.swing.JApplet;
          import javax.swing.JFrame;
          import javax.swing.JLabel;
          import javax.swing.SwingUtilities;
          
          public class NoCursor extends JApplet {
          
              private static final long serialVersionUID = 1L;
          
              public static void main(String[] args) {
               SwingUtilities.invokeLater(new Runnable() {
          
                   @Override
                   public void run() {
                    JApplet applet = new NoCursor();
                    applet.init();
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(applet);
                    applet.init();
                    frame.setSize(500, 400);
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                   }
               });
              }
          
              @Override
              public void init() {
               this.getContentPane().setCursor(
                    Toolkit.getDefaultToolkit().createCustomCursor(
                         new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB),
                         new Point(), "TransparentCursor"));
               this.add(new JLabel("A text label"));
              }
          
          }
          Edited by: pietblok on 17-aug-2010 17:04
          • 2. Re: Window applet and mouse pointer
            843807
            google.com "java hide mouse cursor"

            very first link: [first google link|http://www.rgagnon.com/javadetails/java-0440.html]

            I've actually used that method before and it works.
            • 3. Re: Window applet and mouse pointer
              843807
              Yes, this code solve my problem. Thank you morgalr and pietblok by your answers,

              here is the link to the game applet:

              http://nti.catolica-to.edu.br/Material/Jogos/Applets2/TabuadaEspacial.html

              best regards.