Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Hand Cursor in Applet

Posted on 1998-06-29
7
Medium Priority
?
761 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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.
Suggested Courses

636 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