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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
public class WaitDialog extends JDialog {
private final String wait = "Please, wait while app is retrieving data";
private final int labelsLimit = 3;
private JLabel[] labels = new JLabel[labelsLimit];
private JPanel panel;
private final Dimension dim = new Dimension(320, 210);
public WaitDialog() {
buildComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
private void buildComponents() {
panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
this.getContentPane().add(panel);
panel.setBackground(Color.WHITE);
try {
labels[0] = new JLabel(new ImageIcon(getClass().getResource("waittoplogo.jpg")), JLabel.CENTER);
labels[1] = new JLabel(new ImageIcon(getClass().getResource("wait_a.gif")), JLabel.CENTER);
labels[2] = new JLabel(wait, JLabel.CENTER);
for (int i = 0; i < labelsLimit; i++) {
String location = "";
switch (i) {
case 0:
location = BorderLayout.NORTH;
break;
case 1:
location = BorderLayout.CENTER;
break;
case 2:
location = BorderLayout.SOUTH;
break;
}
panel.add(labels[i], location);
}
} catch (NullPointerException npe) {
JOptionPane.showMessageDialog(null, "Problem with app, exiting", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
this.setMinimumSize(dim);
this.setPreferredSize(dim);
this.setResizable(false);
this.setUndecorated(true);
this.setAlwaysOnTop(true);
this.requestFocus();
this.setVisible(true);
}
public void close() {
this.setVisible(false);
this.dispose();
}
public void updateJLabel(String s) {
System.out.println(s);
final int last = this.labelsLimit - 1;
labels[last] = new JLabel(s);
panel.remove(last);
panel.add(labels[last], last);
panel.updateUI();
}
} |