Solved

Hand Cursor in Applet

Posted on 1998-06-29
7
756 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:pengch
ID: 1224084
Adjusted points to 100
0
 
LVL 2

Accepted Solution

by:
aziz061097 earned 100 total points
ID: 1224085
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
ID: 1224086
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pengch
ID: 1224087
Is there no way using JDK 1.0?
0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1224088
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
ID: 1224089
The problem is, I am trying change the cursor in "Applet", not a independent program.
0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1224090
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 124
servlet example 17 59
how to install java on RHEL image on EC2 4 55
Print Rhino Java Array in Javascript 1 32
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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