Normand Briere
2018-07-07 09ddd38fd4a8a7100c834a5e976f4796fae53541
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
package timeflow.app.ui;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class WaitingDialog extends JFrame {
   
   Timer timer;
   
   public static void main(String[] args)
   {
       new WaitingDialog("Testing", "Hello, world!");
   }
       
   public WaitingDialog(String title, String message)
   {
       super(title);
       Throbber throbber=new Throbber();
       timer=new Timer(50, throbber);        
       getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
       getContentPane().add(throbber);
       getContentPane().add(new JLabel(message));
       setBounds(400,400,300,150);
       setVisible(true);
       timer.start();
   }
   
   public void stop()
   {
       timer.stop();
       setVisible(false);
   }
   
   class Throbber extends JPanel implements ActionListener
   {
       int count=0;
       public void paintComponent(Graphics g)
       {
           int w=getSize().width, h=getSize().height;
           int c=count%256;
           g.setColor(new Color(c,c,c));
           g.fillRect(0,0,w,h);
       }
       @Override
       public void actionPerformed(ActionEvent e) {
           repaint();
           count+=10;
       }
       
       public Dimension getPreferredSize()
       {
           return new Dimension(30,100);
       }
   }
}