Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Changing the Cursor in Java 
 

In this section, you will see how to change the cursor in java.

 

Changing the Cursor in Java

                         

Introduction

Here, you will learn how to change the mouse cursor in java. Changing the cursor means showing cursor in many different  shapes for the different objects.

First button is "Ok" button, when the cursor goes upon it, cursor shape changes to hand shape. If you move the mouse over "Cancel" button, the cursor shape changes to move cursor (MOVE_CURSOR).

In this process the following methods to be used in the program.

add(panel,BorderLayout.CENTER) :
The add() method has been used to add the panel to the frame. The BorderLayout container has the five components such as: NORTH, SOUTH, WEST, EAST and CENTER.

getCursor(): 
This method is used to declaring the predefined cursor to set for the object. This method contains the Cursor properties which indicates the several cursors.

setCursor() :
This method defined in the Component class. It changes the cursor icon when the cursor goes upon the particular component.

getPredefinedCursor() :
The getPredefinedCursor() method returns the cursor object to be specified in the cursor block.

Here is the code of the program :     

import java.awt.*;
import java.awt.event.*;

public class ChangeCursor{
  public static void main(String[] args) {
    Frame f = new Frame("Change cursor");
    Panel panel = new Panel();
    Button comp1 = new Button("Ok");
    Button comp2 = new Button("Cancel");
    panel.add(comp1);
    panel.add(comp2);
    f.add(panel,BorderLayout.CENTER);
    f.setSize(200,200);
    f.setVisible(true);
    Cursor cur = comp1.getCursor();
    Cursor cur1 = comp2.getCursor();
    comp1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    comp2.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    f.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent we){
        System.exit(0);
      }
    });

  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c gui com ide browser class stl ui applet io methods classes method sed apple nested override vi component panel

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

i think the web page is really good for learn java.

Posted by nimmetullah on Thursday, 12.20.07 @ 21:10pm | #43140

i think the web page is really good for learn java.

Posted by nimmetullah on Thursday, 12.20.07 @ 21:09pm | #43139

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.