• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fileReader + GUI

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to add an actionListener to the button
GUI.add(txtTemperatur);
btnMaks.addActionListener(this);//<-------------
GUI.add(btnMaks);
 
kelvin cheung
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a few modifications - all seems working OK, but the layout should
be something other than a FlowLayout.
 
kelvin cheung
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic