Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:48:11+00:00 2026-06-17T07:48:11+00:00

I am having problems with my Scanner. Click the button, and text from the

  • 0

I am having problems with my Scanner. Click the button, and text from the second file should display. I got the button working, however the programme skips straight to the last line of the new textfile. Because of the slow load time, I think it’s because I can’t close my first scanner. I don’t think my layout is helping matters a lot, as there are going to be a lot of text files read one at a time, but writing the second class as an inner class makes things extra complicated it seems.

How do I make the scanner from the second class accessible to the first (and thus, use reader.close() )?
Should I be using nested/inner classes to boot the programme up?
Is there a cleaner method to start the programme and then prime the scanner for later actions?

Lastly, I’ve been trying to conform to SSCCE, am I any close? Thanks for your help

import declarations
public class MihatteFrame extends JFrame implements ActionListener{
....
public MihatteFrame() {
    area
    textfield
    button  
}
displayText method
checkTextFieldText method

public void actionPerformed(ActionEvent e) {
    try {
        if (textField.getText().equals("proceed to the entrance")) {
            Scanner.close();
            Scanner reader2 = new Scanner(new File("(Start) Front Gate.txt"));
            while (reader2.hasNextLine()) {
                String line = reader2.nextLine();
                displayText(line);
                try {
                    if(!line.trim().equals("")){
                                Thread.sleep(1000);
                        }
                    } catch (InterruptedException e) {
                    }   
            }
        } else {
            while (textField.getText() == null) {
                displayText("I`m sorry, could you say that again?");
            }
        }
    } catch (IOException ioe) {
    }
}

x

import declarations
class ShowIntro {
public static void main(String args[]) throws IOException {
MihatteFrame mf = new MihatteFrame();
Scanner reader = new Scanner(new File("(Start) Introduction.txt"));

while (reader.hasNextLine()) {
    String line = reader.nextLine();
    mf.displayText(line);
    try {
        if(!line.trim().equals("")){
        Thread.sleep(1000);
            }
    } catch (InterruptedException e) {
    }       
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:48:12+00:00Added an answer on June 17, 2026 at 7:48 am

    The GUI thread only performs actions when you return from an events it calls you with. This means if you do lots of actions, you will only see the cumulation of these action and if you pause for any reason, your GUI will pause.

    You need to perform the action, in another thread so the GUI thread can update the screen. You also need to use SwingUtils.invokeLater() to update the GUI from a second thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems reading in a text file with java. The text file has
I am having trouble reading from a simple text file and cannot seem to
Im having problems with a method in a class file: public static function getPageLeft($pid)
Having problems compiling this class. I'm working through a book on java and this
I am having problems with my java assignment. I have been working on it
I'm having problems trying to pass an Integer object from a driver class as
This program simply is supposed to eliminate duplicates from an array. However, the second
I've been using a hashmap to store unique words from a text file. Now,
Having problems with a small awk script, Im trying to choose the newest of
Having problems iterating. Problem has to do with const correctness, I think. I assume

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.