• 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

Reading consecutive text file lines using scanner and actionListener event

 
Greenhorn
Posts: 1
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would be grateful if someone can come up with some suggestions please, ( I am currently revising for an exam).I have been having trouble reading consecutive lines from a text file using scanner through an actionListener event (button press or a mouseListener event, mousePressed); so that each button press reads the first line of text and the next button press reads the second line and so on. I cannot use a collection to store the text first.
I have put together a small example of what i am trying. I can read the whole text file no problem and i can read the first line of text without a problem. I have considered using some form of count comparison but cannot get that to work either. There are various commented out statements included as part of my attempts. Thanks



Please ignore my request I have finally solved the problem. By declaring the scanner object as an instance variable and instantiating it in the constructor inside a try catch block and removing the matching code from the button watcher, it all works.
 
reply
    Bookmark Topic Watch Topic
  • New Topic