-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path64_ProgressBar
More file actions
68 lines (56 loc) · 1.62 KB
/
64_ProgressBar
File metadata and controls
68 lines (56 loc) · 1.62 KB
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
66
67
// progress bar = Visual aid to let the user know what an operation is processing
<Main.java>
public class Main {
public static void main(String[] args) {
ProgressBarDemo demo = new ProgressBarDemo();
}
}
<ProgressBarDemo.java> //count upwards
import javax.swing.*;
import java.awt.*;
public class ProgressBarDemo {
JFrame frame = new JFrame();
JProgressBar bar = new JProgressBar();
ProgressBarDemo(){
bar.setValue(0);
bar.setBounds(0,0,420,50);
bar.setStringPainted(true); //percentage will change when set value
bar.setFont(new Font("MV Boli",Font.BOLD,25));
bar.setForeground(Color.red); //fill colour
bar.setBackground(Color.black); //bar ori colour unfilled
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420,420);
frame.setLayout(null);
frame.setVisible(true);
fill();
}
public void fill() {
int counter = 0;
while(counter<=100) {
bar.setValue(counter);
try {
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
counter += 10;
}
bar.setString("Done! :)");
}
/*
//Count downward
public void fill() {
int counter = 500;
while(counter>=0) {
bar.setValue(counter);
try {
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}
counter -= 1;
}
bar.setString("Done! :)");
}
*/
}