Solved

Hand Cursor in Applet

Posted on 1998-06-29
7
754 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

785 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