Welcome to Dream.In.Code
Become a Java Expert!

Join 149,519 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,390 people online right now. Registration is fast and FREE... Join Now!




problem making a busy box

 
Reply to this topicStart new topic

problem making a busy box

manasranjanswain
24 May, 2007 - 03:34 AM
Post #1

New D.I.C Head
*

Joined: 24 May, 2007
Posts: 4


My Contributions
I am trying to make a "busy" box, which is a dialog box which pops up to tell the user that the program is currently doing some processing. Below is the code for the class.

public class BusyBox extends JDialog implements Runnable {

JFrame parent;

public BusyBox(JFrame parent, String title, String message) {
super( parent, title, true );
this.parent = parent;
JLabel label = new JLabel(message);
label.setHorizontalAlignment(JLabel.CENTER);
Container contentPane = getContentPane();
contentPane.add(label, BorderLayout.CENTER);
setSize(new Dimension(300, 125));
setResizable(false);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
}

public void showMessage() {
Thread thread = new Thread(this);
thread.start();
}

public void run() {
setLocationRelativeTo(parent);
setVisible(true);
}

public void done() {
setVisible(false);
}

}

Here's how I use the code:

BusyBox busyBox = new BusyBox(this, "Processing", "Please wait...");
busyBox.showMessage();
// some heavy processing code here
busyBox.done();

The problem I'm facing is that the text of the label on the dialog box does not show up.

User is offlineProfile CardPM
+Quote Post

beef
RE: Problem Making A Busy Box
24 May, 2007 - 05:45 AM
Post #2

D.I.C Head
Group Icon

Joined: 2 Nov, 2006
Posts: 128


My Contributions
It worked fine for me, does the dialog box show up?

Here is what I used to test it.
CODE

package base;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import util.*;
import listeners.*;

public class Tester
{
    private static JFrame f;
    private static JButton b;
    
    private static void makeGui()
    {
        f = new JFrame("Testing a busybox");
        b = new JButton("close");
        
        f.setSize(new Dimension(300,300));
        
        b.addActionListener(new Buttons(f));
        f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
        
        f.add(b);
        f.setVisible(true);
    }
    
    public static void main(String[] args)
    {
        makeGui();
        
        BusyBox busyBox = new BusyBox(f, "Processing", "Please wait...");
        busyBox.showMessage();
        for(int i=0;i<100000;i++){    System.out.println(i);    }
//         some heavy processing code here
        busyBox.done();
    }
}


The import util was the package I stuck your busybox in and the import listeners is just used for the system exit on the button.

I just copy/pasted the busybox in, the only thing I added was 2 imports for swing.* and awt.*
User is offlineProfile CardPM
+Quote Post

manasranjanswain
RE: Problem Making A Busy Box
25 May, 2007 - 01:52 AM
Post #3

New D.I.C Head
*

Joined: 24 May, 2007
Posts: 4


My Contributions
QUOTE(beef @ 24 May, 2007 - 06:45 AM) *

It worked fine for me, does the dialog box show up?

Here is what I used to test it.
CODE

package base;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import util.*;
import listeners.*;

public class Tester
{
    private static JFrame f;
    private static JButton b;
    
    private static void makeGui()
    {
        f = new JFrame("Testing a busybox");
        b = new JButton("close");
        
        f.setSize(new Dimension(300,300));
        
        b.addActionListener(new Buttons(f));
        f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
        
        f.add(b);
        f.setVisible(true);
    }
    
    public static void main(String[] args)
    {
        makeGui();
        
        BusyBox busyBox = new BusyBox(f, "Processing", "Please wait...");
        busyBox.showMessage();
        for(int i=0;i<100000;i++){    System.out.println(i);    }
//         some heavy processing code here
        busyBox.done();
    }
}


The import util was the package I stuck your busybox in and the import listeners is just used for the system exit on the button.

I just copy/pasted the busybox in, the only thing I added was 2 imports for swing.* and awt.*


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:17PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month