Solved

Hand Cursor in Applet

Posted on 1998-06-29
7
753 Views
Last Modified: 2008-02-26
I am using the following code to change the cursor within a applet (source given by anguslai):

Object theFrame=null;
         
    theFrame=getParent();

     while(!(theFrame instanceof Frame) && theFrame!=null) {
           theFrame=((Component)theFrame).getParent();
     }

    if (theFrame!=null) {
               ((Frame)theFrame).setCursor(Frame.HAND_CURSOR);

          But the mouse cursor changed to Window´s "alternate select" cursor. Anyone know how to change the cursor to the "little hand"?
0
Comment
Question by:pengch
  • 4
  • 3
7 Comments
 

Author Comment

by:pengch
Comment Utility
Adjusted points to 100
0
 
LVL 2

Accepted Solution

by:
aziz061097 earned 100 total points
Comment Utility
Cursor in JDK 1.1 is an object in itself. You will have to create an instance of the cursor and then call it. Following is a sample program , it has a Frame and a button on that Frame. If you point the cursor to the button the cursor will become a Hand cursor.

// Save the program in CursorTest.java and compile and run
import java.awt.*;

public class CursorTest extends Frame {

public static void main(String args[]){

Cursor HandCursor = new Cursor(Cursor.HAND_CURSOR);

CursorTest f1 = new CursorTest();
f1.setLayout(new FlowLayout());
f1.setSize(300,200);

Button bt = new Button("Change cursor to HAND when

pointed here");

f1.add(bt);

bt.setCursor(HandCursor);

f1.setVisible(true);

}
}


0
 
LVL 2

Expert Comment

by:aziz061097
Comment Utility
Just a comment : The above program has a line which is broken in to two a dierct cut and paste will require to edit this line .


make these two lines in to one in above program:  

Button bt = new Button("Change cursor to HAND when

pointed here");

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:pengch
Comment Utility
Is there no way using JDK 1.0?
0
 
LVL 2

Expert Comment

by:aziz061097
Comment Utility
In 1.0 you can have a Hand Cursor as follows. I have tested it in 1.1 but this should work fine in 1.0 .

// Save this program in a file CursorTest10.java
import java.awt.*;

public class CursorTest10 extends Frame {

public static void main(String args[]){


CursorTest10 f1 = new CursorTest10();
f1.setLayout(new FlowLayout());
f1.setSize(300,200);

Button bt = new Button("Change cursor to HAND");

f1.add(bt);

f1.setCursor(Frame.HAND_CURSOR);

f1.show();

}
}
0
 

Author Comment

by:pengch
Comment Utility
The problem is, I am trying change the cursor in "Applet", not a independent program.
0
 
LVL 2

Expert Comment

by:aziz061097
Comment Utility
I am afraid NO ! That is a limitation of JDK 1.0 why not move to 1.1 ? If you want to stick with 1.0 you may be forced to bring up a frame. Try instantiating a Frame but don't do a show()and try using it to set the Cursor on the Applet. There are chances that it may work.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changeXy challenge 13 55
wordlen challenge 3 45
wordappend challenge 8 82
JList custom Cell Renderer refresh 15 38
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now