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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:29:41+00:00 2026-06-16T07:29:41+00:00

i have a frame that contain a button and textfield. my porpuse is read

  • 0

i have a frame that contain a button and textfield.

my porpuse is read ID number frome textfield and when clicked on button, my table should display that ID with its name and mark.

my “UserSearchFile.txt” is this:

12 joe 120
14 ted 220
19 alex 560
22 julia 668

my jButton6ActionPerformed whole code is this:

int idS=Integer.parseInt(jTextField2.getText());
      final Vector data = new Vector();
      final Vector column = new Vector();
 File f=new File("D:\\UserSearchFile.txt");
    try{
    FileReader fr=new FileReader(f);
    BufferedReader br1=new BufferedReader(fr);
    String s;
while ((s = br1.readLine()) != null) {
                String[] st = s.split(" ");
                String id = st[0];
                String name = st[1];
                String mark = st[2];
                if (id.equals(String.valueOf(idS))) {
try {
            String line2;
FileInputStream fis = new FileInputStream("D:\\UserSearchFile.txt");
        BufferedReader br2 = new BufferedReader(new InputStreamReader(fis));
      StringTokenizer st1 = new StringTokenizer(br2.readLine(), " ");
              while (st1.hasMoreTokens())
               column.addElement(st1.nextToken());
                while ((line2 = br2.readLine()) != null) {
                       StringTokenizer st2 = new StringTokenizer(line2, " ");
                        while (st2.hasMoreTokens())
                                data.addElement(st2.nextToken());
                }
                br2.close();
        } catch (Exception e) {
                e.printStackTrace();
        }
                }
            }
        } catch (IOException ex) {
           Logger.getLogger(MainFrame1.class.getName()).log(Level.SEVERE, null, ex);
        }

 jTable1.setModel(new AbstractTableModel() {

        public int getRowCount() {
           return data.size() / getColumnCount();
        }

        public int getColumnCount() {
            return column.size();
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            return (String) data.elementAt((rowIndex * getColumnCount())
                        + columnIndex);
        }
    });
    jTable1.setVisible(true);

please help me and tell me how to write cleany and simple.

  • 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-16T07:29:43+00:00Added an answer on June 16, 2026 at 7:29 am

    Start by using meaningful names for your variables and methods. jTable1, br1, br2 and jButton6ActionPerformed are not acceptable names.

    Then try to split a complex method into 2 or three operations, themselves split into 2 or three operations, etc. Each operation should be a method call. For example:

    private void readButtonClicked() {
        String id = idTextField.getText();
        Student student = findStudentWithId(id);
        showStudentInGUI(student);
    }
    
    private Student findStudentWithId(String id) {
        List<String> lines = readLinesInFile();
        List<Student> students = transformLinesIntoStudents(lines);
        Student studentWithId = findStudentWithId(students, id);
    }
    
    private Student findStudentWithId(List<Student> students, String id) {
        for (Student student : students) {
            if (student.getId().equals(id)) {
                return student;
            }
        }
        return null;
    }
    
    private List<Student> transformLinesIntoStudents(List<String> lines) {
        List<Student> students = new ArrayList<Student>(lines.size());
        for (String line : lines) {
            students.add(parseStudentLine(line);
        }
        return students;
    }
    
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIView that contain another subview. The subview's frame is outside of
Let's assume that we have a data frame x which contains the columns job
I was just wondering about something. I have a frame that loads pages and
I have a data frame that is some 35,000 rows, by 7 columns. it
I have a data frame that's about ts1[100, 2000] in dimension as follows: >
I have a data.frame that looks like this: > head(ff.df) .id pio caremgmt prev
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that has come about from running some
I have a data frame in R that looks like this: > TimeOffset, Source,
Do older iPods and iPhones have a frame rate of 60fps? I'm finding that

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.