Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading consecutive text file lines using scanner and actionListener event  RSS feed

Posts: 1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
Why should you try IntelliJ IDEA ?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!