1 16 17 package org.mc4j.console.connection; 18 19 import javax.swing.*; 20 import java.awt.*; 21 22 28 public class ProgressDialog extends JDialog { 29 30 private JProgressBar progressBar; 31 32 private int max; 33 34 public ProgressDialog(int max) { 35 this.max = max; 36 37 init(); 38 } 39 40 private void init() { 41 JLabel title = new JLabel("Loading " + max + " MBeans."); 42 progressBar = new JProgressBar(0, max); 43 44 setTitle("Loading " + max + " MBeans."); 45 46 getContentPane().setLayout(new GridBagLayout()); 47 GridBagConstraints c1 = new GridBagConstraints(); 48 c1.gridx = 0; 49 c1.gridy = 0; 50 c1.insets = new Insets(10,10,10,10); 51 c1.anchor = GridBagConstraints.NORTHWEST; 52 53 getContentPane().add(title, c1); 54 55 GridBagConstraints c2 = new GridBagConstraints(); 56 c2.gridx = 0; 57 c2.gridy = 1; 58 c2.fill = GridBagConstraints.HORIZONTAL; 59 c2.insets = new Insets(10,10,10,10); 60 61 progressBar.setMinimumSize(new Dimension(240,25)); 62 getContentPane().add(progressBar, c2); 63 64 GridBagConstraints c3 = new GridBagConstraints(); 65 c3.fill = GridBagConstraints.HORIZONTAL; 66 c3.gridwidth = GridBagConstraints.REMAINDER; 67 c3.anchor = GridBagConstraints.EAST; 68 JButton cancelButton = new JButton("Cancel"); 69 getContentPane().add(cancelButton, c3); 70 71 setSize(340,120); 72 Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); 73 74 setLocation( 75 dim.width/2 - getWidth()/2, 76 dim.height/2 - getHeight()/2 77 ); 78 79 setVisible(true); 81 } 82 83 public void setValue(int value) { 84 progressBar.setValue(value); 85 } 86 87 public void close() { 88 setVisible(false); 89 dispose(); 90 } 91 92 public static void main(String [] args) { 93 ProgressDialog dialog = new ProgressDialog(100); 94 dialog.setVisible(true); 95 } 96 } 97 | Popular Tags |