File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes fileReader + GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "fileReader + GUI" Watch "fileReader + GUI" New topic
Author

fileReader + GUI

kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
hi,
i want to make a program that is able to read :
- year
- temperature
in a .txt file which looks something like this :
1871
3.1
1872
4.8
........

there should be :
2 TEXTFIELDS (type in the filename of the .txt file, and it displays on the second field)
3 BUTTONS (max temperature, min temperature, average temperature).

but i get some problems,
it does nothing when i press the MAX button.

anyone can help?

should look something like this :

[ April 13, 2004: Message edited by: kelvin cheung ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
You need to add an actionListener to the button
GUI.add(txtTemperatur);
btnMaks.addActionListener(this);//<-------------
GUI.add(btnMaks);
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
hi Michael Dunn,
i forgot to do that...
thanks for telling me ...
but it still does nothing when i press the MAKS button.
how come?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
In actionPerformed() you call a method finnMaks(f), but you don't assign
the returned value to anything.
If your intention is to assign the value to the variable maks, and use the
value of maks in actionPerformed(), your problem is the declaration of maks
twice - once as a class variable, another as a local variable in finnMaks()
- the local variable will take precedence from within finnMaks(), so when
finnmaks() returns, the local variable dies and the class variable (which
will/should(?) have been initialized with a 0.00 value)is used in
actionPerformed()
Perhaps the easiest fix is (in actionPerformed())
maks = finnMaks(f);
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
hi Michael Dunn,
thank you for the fix!
it sounded difficult for me.
but anyway...
my code is now :

---------
when i press the MAKS button i get : 4.8 (which is the highest temperature).
1) how do i get the year too?
like this "highest temperature is 4.8 in year 1872" ?
2) and on "antall registreringer" it only shows "0".
but it should show "7".
any ideas ?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Here's a few modifications - all seems working OK, but the layout should
be something other than a FlowLayout.
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
hi Michael Dunn !
thank you so much for taking your own time and helped me.
i really appreciate it.
i will study the code closer.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: fileReader + GUI