-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressBar.java
More file actions
74 lines (60 loc) · 2.2 KB
/
ProgressBar.java
File metadata and controls
74 lines (60 loc) · 2.2 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
68
69
70
71
72
73
74
import java.awt.Color;
import javax.swing.JProgressBar;
/**
* A class used to create a progress bar while the user waits for ChatGPT's response
* @see Gui#openResponseFrame()
*/
public class ProgressBar extends Thread {
//Different messages shown while the bar is filling up
static String s1 = "Composing the prompt";
static String s2 = "Sending your message to ChatGPT";
static String s3 = "Preparing the response";
static String s4 = "Communicating with Pavlos";
static String s5 = "Gathering information about OPA";
static String s6 = "Asking graduate students";
static String s7 = "Getting results from exams";
static String s8 = "Counting answers";
static String s9 = "Scanning facial characteristics";
static String s10 = "Calculating shortest route from your house";
static String[] barMessages = new String[] {s1, s2, s3, s4, s5, s6, s7, s8, s9, s10};
public JProgressBar bar;
/**
* Default constructor utilizing the default constructor of the JProgressBar class
* @see javax.swing.JProgressBar
*/
public ProgressBar() {
this.bar = new JProgressBar();
bar.setValue(0);
bar.setStringPainted(true);
bar.setForeground(new Color(158, 22, 22));
bar.setBackground(Color.WHITE);
bar.setBounds(568, 382, 400, 100);
}
/**
* Method used to simulate the filling of the bar
* Overrides the run() of the Thread class
* @see Thread#run()
*/
@Override
public void run() {
int value = bar.getValue();
int i = 0;
while (value <= 100) {
bar.setValue(value);
value = bar.getValue();
bar.setString(barMessages[i]);
if (value == 100) {
bar.setString("Done");
}
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
value += 1;
//Selecting a random integer from 0 to 9 in order to show different messages
i = (int)(Math.random()*10);
}
bar.setVisible(false);
}
}