🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.java
2 messages
2 total messages Started by Thomas de Massy Sat, 13 Sep 1997 05:47
How do I change the cursor to an hand in an applet ?
#989
Author: Thomas de Massy
Date: Sat, 13 Sep 1997 05:47
19 lines
1556 bytes
I would like to know how do I chage the mouse cursor
to the hand cursor when the mouse enter in the applet
and change it to the arrow when it exits it.

I know I have to use frame but I don't want my applet
to be in a window. I want to use a standard applet.

Could you send me the code of a simple applet that
doesn't make anything except change the mouse
cursor ?

Thanks

P.S. send me the answer by email too.
-- 
----------------------------- KRUST--------------------------------
Thomas de Massy (Krusty)
tomasd@axess.com
http://www.geocities.com/SoHo/Studios/4407/
Re: How do I change the cursor to an hand in an applet ?
#990
Author: David S. Dagon
Date: Sun, 14 Sep 1997 20:00
59 lines
3131 bytes
Thomas de Massy wrote:

> I would like to know how do I chage the mouse cursor
> to the hand cursor when the mouse enter in the applet
> and change it to the arrow when it exits it.

Hi Thomas,

Have a look at this code (not tested):
//---------------------------------------

import java.awt.*;
import java.applet.*;

public class cursor extends Applet {
    Cursor hand =
(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
    Cursor normal=
(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
    /* Want other cursors? Look at API constants java.awt.Cursor */
    Label label1, label2;
    public void init()
        {
            // just to demonstrate
            super.init();
            setLayout(null);
            resize(283,190);
            label1=new Label("Pointer Here", Label.CENTER);
            add(label1);
            label1.reshape(68,75,147,15);
            label2=new Label("Hand Up Here", Label.CENTER);
            add(label2);
            label2.reshape(68,0,147,50);
        } //init
    public boolean mouseMove(java.awt.Event evt, int x, int y)
        {
            /* This is terrible style; the labels will interfere with
mouseMove; this is just to demonstrate setCursor(cursor); use better 1.1
event handlers */
            showStatus("x:"+x+ " y:"+y);
            // note the method setCursor(cursor);
            if (y>50) setCursor(normal);
            else setCursor(hand);
            return true;
        } // rodentMove
} // class

Instead of mouseMove, use mouseEnter(java.awt.Event evt, int x, int y)
{...},
and mouseExit(java.awt.Event evt, int x, int y) {...}, or any other
action handler you wish.

Side Note: I'm sure someone's hard at work on a 1+ Meg bean to add a few
other cursor shapes.  Perhaps someone is even hawking a class file you
can use.  No doubt the future JDK 1.5 will be cluttered with several
additional shapes as well.  Does anyone get the impression things are
getting complicated as Java matures?

David
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads