Solved

Hand Cursor in Applet

Posted on 1998-06-29
7
758 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
Industry Leaders: 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

726 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