Hack Forums
[Java] System information program - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] System information program (/showthread.php?tid=5597133)



System information program - Mαxim - Apr 11, 2017

Hello,

I am trying to make a system information program with a graphical user interface. I want to grab things such as available processors and such and display them in the program.

I am using WindowBuilder in Eclipse. I am just wondering, where to i input the information if i want it to run instant when you run the program? I want to set for example:

Code
Runtime.getRuntime().freeMemory()

As a text field. By using like text1.setText() or whatever.

Anyone who can help me get started?


* - Weco - Apr 11, 2017

Put it
1) in your main method after the initialization of the GUI
2) After the text field was created

If you want continuous updates, you could use
Code
...
new Thread(new Runnable({
@Override
public void run() {

while(booleanStillUpdating){
Thread.sleep(TimeYOuWantTOSleepInMSHere)
//set the tetx of the text field again
}

}
}).start();
...



* - Mαxim - Apr 12, 2017

(Apr 11, 2017 03:05 AM)Weco Wrote:  Put it
1) in your main method after the initialization of the GUI
2) After the text field was created

If you want continuous updates, you could use
Code
...
new Thread(new Runnable({
@Override
public void run() {

while(booleanStillUpdating){
Thread.sleep(TimeYOuWantTOSleepInMSHere)
//set the tetx of the text field again
}

}
}).start();
...

Thanks, worked well when I placed it after the textfields.

And I appreciate the lil extra part, will for sure use it.

This is what it looks like atm:

[Image: 7afMLp3.png]

Anyone know how to get CPU temp and such?


* - Weco - Apr 12, 2017

(Apr 12, 2017 03:14 AM)Mαxim Wrote:  Thanks, worked well when I placed it after the textfields.

And I appreciate the lil extra part, will for sure use it.

This is what it looks like atm:

[Image: 7afMLp3.png]

Anyone know how to get CPU temp and such?
For getting CPU Temperature you would probably need to call natives outside the JVM. But you could get quite some Information from OperatingSystemMXBean
(JavaDocs: http://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html)

And you can set the text of the text labels directly while creating them, for example:
JLabel os = new JLabel(System.getProperty(nameOS));