• Post Reply Bookmark Topic Watch Topic
  • New Topic

Daemon thread, filewriter, text box, overview button

 
Eugene Litvinov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm writting a daemon thread program in Java. This thread reads the metadata about the processor. I'm used hyperic-sigar llibrary. After that, save it as a "timer.txt" file. And repeat it until the file size does not exceed 5 MB. Once the file exceeds the size, the program renames it to "timer_dd.MM.yyyy_h.mm.ss.txt" and creates a second "timer.txt", and continues repeat it until the thread do not stop.

My problem is that I can't write the results to a file. And this must be done with GUI. I implemented a button to start or stop. But still need to make a button with the field to select the location to save "timer.txt" and a text box where the same result should be displayed.
Help me please finish the program.
Here is my code and link to library. http://sourceforge.net/projects/sigar/
First class for GUI.



My second class with thread code and filewriter. filewriter stage doesnt work. i marked this stage "//"



Sorry fo my english -_-
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eugene Litvinov wrote:I implemented a button to start or stop. But still need to make a button with the field to select the location to save "timer.txt" and a text box where the same result should be displayed.

Well you've implemented the button, so obviously you know something about Swing, so what exact problems are you having with the other elements ?
What have you tried and in what way did it not do what you wanted it to do ?

Eugene Litvinov wrote:My second class with thread code and filewriter. filewriter stage doesnt work

ItDoesntWorkIsUseless
 
Eugene Litvinov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, i wrote a little unclear. Part of the code does not work because it is not finished. And I don't know how to finish it, don't know how to output the result in timer.txt. I know a little Swing, but how to display the result in a text box and create overview button for select a location for the file creation, I do not know.
Well basically I just need a GUI with choice where create the file, and how to write the result in it.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tool of choice for selecting a file or directory would be the JFileChooser class.
 
Eugene Litvinov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:The tool of choice for selecting a file or directory would be the JFileChooser class.

Thanks, now i have to learn how to output the result.
 
Eugene Litvinov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Made with JFileChooser. But I still can not make the daemon writes the results to a text file.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing I don't understand is why you let the user select files and directories, but only do something with the result if a directory is chosen.

fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
...
File file = fileChooser.getSelectedFile();
if (file.isDirectory()) {


Some comments and questions: 1) Is the Timer run at all? 2) Why is a Timer used - what is that supposed to accomplish? 3) What is the "t.restart()" supposed to accomplish? 4) Don't forget to close the FileWriter. 5) What *is* happening when this code is run? Which lines of code do or do not get executed? How is that different from what you were expecting?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!