Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change a cursor of your Java Application Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
04-Aug-04
Category
Java-API
Language
JBuilder All Versions
Views
361
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Darley, F. Joe
Reference URL:
			1   
2   package samplecode;
3   
4   import java.awt.*;
5   import java.awt.event.*;
6   import javax.swing.*;
7   
8   /**
9    * <p>Title: Cursor Change </p>
10   * <p>Description: This program shows how to change the cursor
11   * of the mouse .</p>
12   * <p>Company: Developer's super Page.com</p>
13   */
14  
15  
16  public class SampleFrame extends JFrame {
17    JPanel contentPane;
18    BorderLayout borderLayout1 = new BorderLayout();
19    JPanel jpnlMain = new JPanel();
20    Button button1 = new Button();
21  
22    //Construct the frame
23    public SampleFrame() {
24      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
25      try {
26        jbInit();
27      }
28      catch(Exception e) {
29        e.printStackTrace();
30      }
31    }
32  
33    //Component initialization
34    private void jbInit() throws Exception  {
35      contentPane = (JPanel) this.getContentPane();
36      contentPane.setLayout(borderLayout1);
37      this.setSize(new Dimension(400, 300));
38      this.setTitle("Cursor Change");
39      jpnlMain.setLayout(null);
40      contentPane.setMinimumSize(new Dimension(300, 300));
41      contentPane.setPreferredSize(new Dimension(300, 256));
42      jpnlMain.setDebugGraphicsOptions(0);
43      jpnlMain.setMinimumSize(new Dimension(400, 256));
44      jpnlMain.setPreferredSize(new Dimension(400, 256));
45      button1.setLabel("button1");
46      button1.setBounds(new Rectangle(137, 92, 105, 37));
47      button1.addActionListener(new SampleFrame_button1_actionAdapter(this));
48      contentPane.add(jpnlMain,  BorderLayout.CENTER);
49      jpnlMain.add(button1, null);
50    }
51  
52    //Overridden so we can exit when window is closed
53    protected void processWindowEvent(WindowEvent e) {
54      super.processWindowEvent(e);
55      if (e.getID() == WindowEvent.WINDOW_CLOSING) {
56        System.exit(0);
57      }
58    }
59  
60  
61  
62    void button1_actionPerformed(ActionEvent e) {
63      //This function changes the cursor of the mouse
64      this.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
65      
66  /* Here is a list of other popular Cursors
67    
68     Cursor.E_RESIZE_CURSOR;
69      Cursor.HAND_CURSOR;
70      Cursor.MOVE_CURSOR
71      Cursor.CROSSHAIR_CURSOR 
72      Cursor.WAIT_CURSOR */
73      
74    }
75  }
76  
77  class SampleFrame_button1_actionAdapter implements java.awt.event.ActionListener {
78    SampleFrame adaptee;
79  
80    SampleFrame_button1_actionAdapter(SampleFrame adaptee) {
81      this.adaptee = adaptee;
82    }
83    public void actionPerformed(ActionEvent e) {
84      adaptee.button1_actionPerformed(e);
85    }
86  }
87  


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC