• 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

How to iterate through an Array of objects and a file at the same time?

 
Ranch Hand
Posts: 41
Eclipse IDE Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a scenario where I have an Array of CurriculumSubject objects (which in turn has creted 15 JTextField object instances) and then a text file.

I want to iterate through the CurriculumSubject Array (and each JTextField for each subject) and go through the text file line by line, setting each JTextField to one line - and then move on to the next.

Currently, I have this method which receives a File object:



How can I integrate a BufferedReader in to this so that as I move through the 15 JTextFields, the BufferedReader reads the next line of the file?

TIA
Adam
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need a reader for text fields? Can’t you use their getText() method?
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell misunderstood. i see what you want to do. set the texFields from info in the file. if someone doesn't answer first i'll see if i can find something like that.
i havent read this but it seems like what you want
read file
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Randall - you are correct. The BufferedReader is to handle the text file and go through the file line by line. I already have managed to access the JTextFields through set and get, so that part of the problem is sorted - it's reading the file line by line that I really need help with. Thanks.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Cripps wrote:it's reading the file line by line that I really need help with.


Well BufferedReader.readLine() returns the next line if there is one; or null if there isn't. Maybe that'll help.

Winston
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Winston. However, I will need to iterate through the file - how do I knit the two iterations together?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Cripps wrote:Thanks Winston. However, I will need to iterate through the file - how do I knit the two iterations together?


I suggest you have a think about it and try something yourself. I've already given you all the information you need to write a read loop of your own using either for or while.

Winston
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so true. often i post questions here and then after i think about it, i come up with the answer.
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic