• 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

Calling ArrayList variables contained in one class into another class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings all.

I am trying to organise my code into classes that make sense, so I created a FileIOManagement class that I want to handle all the reading from text files etc. Currently, the methods I use to read files live in the GUI class that displays the data, but I want to be able to separate GUI and other logic.

This is the code for my current FileIOManagement class:




This is the class that I want to be able to show the data from the file reading that is done by the FileIOManagement class. I have commented out the lines of code, I have moved into the FileIOManagement class:




How would you recommend I go about this? I guess what I need to know is how to create an arraylist object in the FileIOManager class, and pass it to the ReportGUI class.

Thanks.
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you need to add a method that returns a List.

However I'm not sure why you are splitting each line up into separate lists. Surely all the information on a single line is logically related? Does each line represent a different course? If so, I would expect a class called Course that encapsulates all the information on a line, and then a list of Course instances.
 
Wade Gerrits
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike. J. Thompson wrote:Well you need to add a method that returns a List.

However I'm not sure why you are splitting each line up into separate lists. Surely all the information on a single line is logically related? Does each line represent a different course? If so, I would expect a class called Course that encapsulates all the information on a line, and then a list of Course instances.



Hi Mike, thanks for the reply.

I have split the lines because each split populates a different GUI element. For example, the first split fills a combobox full of course data, the second split fills a combobox full of examiner names etc etc. Probably far from best practice but I am still learning.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Agree with Mike: get a method which reads all the lines in your file into a List. Then you can use the List any way you like. You can even make it read‑only with this method
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Passing up on critiquing your design as the others have... the simplest way to achieve your requirement is by following the notion of object-oriented design by providing getter methods for the information needed from the class.

You can either provide access individually:


Or you can provide access as a packaged unit:


To get information out of the packaged unit you could write:
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely rather than a List<List<Foo>> you would return a CourseProgramme object or similar with getCourse() and getNames() methods which return Lists.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic