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 8429255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:17:05+00:00 2026-06-10T05:17:05+00:00

I am looking for a quick fix to this problem I have: Here is

  • 0

I am looking for a quick fix to this problem I have: Here is my code:

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

public class Directory{
    public static void main(String args[]) throws IOException{

    JFrame frame = new JFrame("Directory");
    frame.setPreferredSize(new Dimension(300,300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JProgressBar searchprogress = new JProgressBar();
    JPanel panel = new JPanel();
    final JButton searchbutton = new JButton("Search");
    final JTextField searchfield = new JTextField();
    searchfield.setPreferredSize(new Dimension(100,30));
    searchprogress.setPreferredSize(new Dimension(200, 30));
    searchbutton.setLocation(100, 100);


    /*                  Start Buffered Reader                       */
    BufferedReader br = new BufferedReader(new FileReader("test1.txt"));
    String housetype = br.readLine();
    String housenumber = br.readLine();
    String housestreet = br.readLine();
    String housepostal = br.readLine();
    String houseplace = br.readLine();
    String seperation = br.readLine();
    /*                  Finish Buffered Reader                      */



    /*                      Start Content Code                      */
    JButton done = new JButton("Done");
    done.setVisible(false);
    JLabel housetype_label = new JLabel();
    JLabel housenumber_label = new JLabel();
    JLabel housestreet_label = new JLabel();
    JLabel housepostal_label = new JLabel();
    JLabel houseplace_label = new JLabel();


    /*                      Finish Content Code                     */

    /*                      Start Button Code                       */

    searchbutton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae)
        {
            String searchquery = searchfield.getText();
            searchprogress.setValue(100);
            searchfield.setEnabled(false);
            if(searchquery.equals(housetype)){
                System.out.println("We Have Found  A Record!!");
            }}
        });


    /*                      Finish Button Code                      */
    /*                          Test Field                          */


    /*                      End Test Field                          */

    panel.add(searchfield);
    panel.add(done);
    panel.add(searchbutton);
    panel.add(searchprogress);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);


}
}

Basically After I wrote this code, Eclipse told me I had to change the modifier of housetype, to final. Which truly won’t do, because I need to be a changing value if its going to go trough different records.
PLEASE HELP ME! D:

  • 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-10T05:17:06+00:00Added an answer on June 10, 2026 at 5:17 am

    You have several options here:

    • The quickest would be to do what Eclipse tells you, actually it is Java that tells you that. In order to be able to use method local variables inside inner classes inside the method, the variables must be final.
    • Another option is to declare the housetype variable as an instance variable, immediately after the class definition. But, using it in the static main method means that the variable needs to be static too, which makes it a class variable.
    • Another one would be to keep the code as you have, but declare an extra variable like below and then use the house variable inside the inner class instead of housetype. See the entire code below:

      public class Directory {
        public static void main(String args[]) throws IOException {
      
          JFrame frame = new JFrame("Directory");
          frame.setPreferredSize(new Dimension(300, 300));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      
          final JProgressBar searchprogress = new JProgressBar();
          JPanel panel = new JPanel();
          final JButton searchbutton = new JButton("Search");
          final JTextField searchfield = new JTextField();
          searchfield.setPreferredSize(new Dimension(100, 30));
          searchprogress.setPreferredSize(new Dimension(200, 30));
          searchbutton.setLocation(100, 100);
      
          /* Start Buffered Reader */
          final List<String> housetypes = new ArrayList<String>();
          String line = "";
          BufferedReader br = new BufferedReader(new FileReader("test1.txt"));
          while (line != null) {
              line = br.readLine();
              housetypes.add(line);
              String housenumber = br.readLine();
              String housestreet = br.readLine();
              String housepostal = br.readLine();
              String houseplace = br.readLine();
              String seperation = br.readLine();
          }
          /* Finish Buffered Reader */
      
          /* Start Content Code */
          JButton done = new JButton("Done");
          done.setVisible(false);
          JLabel housetype_label = new JLabel();
          JLabel housenumber_label = new JLabel();
          JLabel housestreet_label = new JLabel();
          JLabel housepostal_label = new JLabel();
          JLabel houseplace_label = new JLabel();
      
          /* Finish Content Code */
      
          /* Start Button Code */
          searchbutton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                  String searchquery = searchfield.getText();
                  searchprogress.setValue(100);
                  searchfield.setEnabled(false);
                  for (String housetype : housetypes) {
                      if (searchquery.equals(housetype)) {
                          System.out.println("We Have Found  A Record!!");
                      }
                  }
              }
          });
      
          /* Finish Button Code */
          /* Test Field */
      
          /* End Test Field */
      
          panel.add(searchfield);
          panel.add(done);
          panel.add(searchbutton);
          panel.add(searchprogress);
          frame.add(panel);
          frame.pack();
          frame.setVisible(true);
        }
      }
      
    • There are even more options, but these are the quickest.

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

Sidebar

Related Questions

Really quick here... I think I have the answer, but just looking for some
I have a feeling this will be a quick fix, given that I started
Looking at Thrift and Google Protocol Buffers to implement some quick RPC code. Thrift
quick and very basic newbie question. If i have list of dictionaries looking like
I am looking for a fast (as in huge performance, not quick fix) solution
I am looking for quick reference guide(s) for both OO and C++. I have
QUICK ANSWER : For those of you who reach this page via Google looking
I'm looking for a quick code/function that will detect if a page contains a
I'm sure this is a quick fix, but it's really got me scratching my
I was looking for a quick PHP function that, given a string, would count

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.