-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUpdateCpuStatus.java
More file actions
64 lines (51 loc) · 1.69 KB
/
Copy pathUpdateCpuStatus.java
File metadata and controls
64 lines (51 loc) · 1.69 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
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
public class UpdateCpuStatus extends SwingWorker<Void, Integer> {
private CpuInfo processorInfo = new CpuInfo();
private JTextPane txtCpuStatus;
private JProgressBar cpuLoadBar;
public UpdateCpuStatus(JTextPane txtCpuStatus, JProgressBar cpuLoadBar){
this.txtCpuStatus = txtCpuStatus;
this.cpuLoadBar = cpuLoadBar;
publish(1);
}
@Override
protected Void doInBackground() throws Exception {
while(true){
publish(1);
Thread.sleep(1000);
}
}
@Override
protected void process(List<Integer> chunk) {
updateStatus();
}
public void updateStatus(){
processorInfo.updateValue();
ArrayList<String> temps = processorInfo.getTemp();
//Cpu Freq and temperature
String cpuStatus = "<html>" +
"<p><strong>Cpu frequency:</strong></p>" +
"<table>"+
"<tr>"+
"<td>"+ processorInfo.getActFreq() +"</td>"+
"<td>"+ processorInfo.getMinFreq() +"</td>"+
"<td>"+ processorInfo.getMaxFreq() +"</td>"+
"</tr>"+
"</table>"+
"<p><strong>Cpu temperature:</strong></p>" +
"<table>"+
"<tr>";
for (String temp : temps) {
cpuStatus = cpuStatus + "<td>"+temp +"</td>";
}
cpuStatus = cpuStatus +
"</tr>"+
"</table>"+
"</html>";
txtCpuStatus.setText(cpuStatus);
//Cpu load
cpuLoadBar.setValue(Integer.parseInt(processorInfo.getload()));
}
}