sandip chitale's blog    Sandip Chitale's blog (scblog)
NOTE: I have moved many of my modules to NetBeans Plugin Portal . Please check there for latest versions of modules described on this blog.
20060201 Wednesday February 01, 2006

Good (not!), bad, ugly?

WaitCursor.java

import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import sun.security.krb5.internal.crypto.e;

public class WaitCursor {
    public static void main(String[] args) {
        final JFrame    frame = new JFrame("Wait Cursor");

        JMenuBar        menuBar               = new JMenuBar();
        JMenu           fileMenu              = new JMenu("File");
        JMenuItem       launchLongRunningTask = new JMenuItem("Launch Long Running Task");

        launchLongRunningTask.addActionListener(new ActionListener() {
                public void actionPerformed(final ActionEvent e) {
                    // At least show wait cursor
                    SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            }
                        });
                    SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                try {
                                    // simulated long running operation
                                    Thread.currentThread().sleep(10000);
                                } catch (InterruptedException e) {
                                    System.err.println(e.getMessage());
                                } finally {
                                    // reset the cursor to default
                                    frame.setCursor(Cursor.getDefaultCursor());
                                }
                            }
                        });
                }
            });
        
        fileMenu.add(launchLongRunningTask);
        menuBar.add(fileMenu);
        frame.setJMenuBar(menuBar);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(400, 400, 200, 100);
        frame.setVisible(true);
    }
}

Comments?
Posted by sandipchitale ( Feb 01 2006, 11:42:58 PM PST ) Permalink Comments [0]


Trackback URL: http://blogs.sun.com/scblog/entry/good_bad_ugly
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed








« December 2009
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today

Get NetBeans 5.5

Locations of visitors to this page

Today's Page Hits: 275


XML
All
/Creator
/General
/Hobby
/Java
/JavaScript
/Mozilla
/NetBeans
/Ubuntu
/VisualWeb
/VisualWebPack
/Web 2.0

XML
All
/Creator
/General
/Hobby
/Java
/JavaScript
/Mozilla
/NetBeans
/Ubuntu
/VisualWeb
/VisualWebPack
/Web 2.0

scblog
scblog