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

  • Home
  • SEARCH
  • 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 7947967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:35:09+00:00 2026-06-04T01:35:09+00:00

I have created a JFrame and a put a textfield and the button.in the

  • 0

I have created a JFrame and a put a textfield and the button.in the textfield i have put a name read from a text file.know i want click the button and aopen a knew window in which i want to put the name + other information from the same file.

here is my code:
This is my main frame

   package Frontend;

   import Business.ShowDetails;
   import model.*;
   import java.awt.*;
   import java.awt.event.*;
   import java.io.*;
   import java.util.*;
   import javax.swing.*;

 public class Gui {
  //String file=" ";
  private JFrame frame;
  private JPanel panel1 ;
  private JPanel panel2;
  private JPanel panel;
  private JTextField nume1;
  private JTextField nume2;
  private JTextField nume3;
  private JTextField nume4;
  private JTextField nume5;
  private JButton edit1;
  private JButton edit2;
  private JButton edit3;
  private JButton edit4;
  private JButton edit5;
  private final String file = "Persoane.txt";


public Gui(){
   fereastra();
   readFile(file);
}

public void fereastra(){

    frame = new JFrame();
    panel = new JPanel(new FlowLayout());
    panel1 = new JPanel(new GridLayout(5,2,1,7));
    panel2 = new JPanel(new GridLayout(5,2,1,1));

    nume1 = new JTextField(15);
    nume2 = new JTextField(15);
    nume3 = new JTextField(15);
    nume4 = new JTextField(15);
    nume5 = new JTextField(15);

    edit1 = new JButton("Edit");
    edit2 = new JButton("Edit");
    edit3 = new JButton("Edit");
    edit4 = new JButton("Edit");
    edit5 = new JButton("Edit");

    panel1.add(nume1);
    panel2.add(edit1);
    panel1.add(nume2);
    panel2.add(edit2);
    panel1.add(nume3);
    panel2.add(edit3);
    panel1.add(nume4);
    panel2.add(edit4);
    panel1.add(nume5);
    panel2.add(edit5);

    ButtonHandler handler = new ButtonHandler();    
    edit1.addActionListener(handler);                             
    edit2.addActionListener(handler);
    panel.add(panel1);
    panel.add(panel2);
    frame.add(panel);
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    frame.setSize(300, 200);
    frame.setVisible(true);
}
public String readFile(String filename){
    try{
         String line="";
         Persoana p ;
         BufferedWriter bw = null;
         ArrayList<Persoana> listOfPersons;

          //creez o lista de persoane
         listOfPersons = new ArrayList<Persoana>();
         //citesc fisierul Persoane.txt
        FileReader  file1 =new FileReader(filename);
         BufferedReader br1 = new BufferedReader(file1);

        while((line = br1.readLine())!= null){
          //elimin prima linie din fisier

         if(!line.trim().contains("ID")){
         String[] attributes = line.split(";");// separ fiecare linie in tokenuri

            p = new Persoana(); // make a new person
            p.setId(Integer.parseInt(attributes[0]));
            p.setNume(attributes[1]);
            p.setPrenume(attributes[2]);
            p.setDataNasterii(attributes[3]);
            p.setProfesie(attributes[4]);

            listOfPersons.add(p);
         }

      }
         int i = 0;
        while (i < listOfPersons.size()){
            if(i == 0){
                 p = listOfPersons.get(i);
                 nume1.setText(p.getNume() + " " +p.getPrenume());
                 nume1.getText();
            }
            if(i == 1){
                 p = listOfPersons.get(i);
                 nume2.setText(p.getNume() + " " +p.getPrenume());
                 nume2.getText();
            }
             if(i == 2){
                 p = listOfPersons.get(i);
                 nume3.setText(p.getNume() + " " +p.getPrenume());
                 nume3.getText();
            }
             if(i == 3){
                 p = listOfPersons.get(i);
                 nume4.setText(p.getNume() + " " +p.getPrenume());
                 nume4.getText();
            }
             if(i == 4){
                 p = listOfPersons.get(i);
                 nume5.setText(p.getNume() + " " +p.getPrenume());
                 nume5.getText();
            }

             i++;
         }
         br1.close();
    }
    catch(IOException ex){
        System.out.println("Error opening file.");
        System.exit(1);
    }
   return file;
}

  // inner class for button event handling
    private class ButtonHandler implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                    if (e.getSource() == edit1) {
                            new ShowDetails();

                    }
                    if (e.getSource() == edit2) {
                            new ShowDetails();
                    }
        }
}
}

this is my second cclass:

  package Business;

  import Frontend.*;
   import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;




  public class ShowDetails extends JFrame{

  Gui gui;


  public ShowDetails(){

    this.gui = gui;
    fereastra();
}

public void fereastra(){
    JPanel panel = new JPanel(new GridLayout(2, 2));
    JTextArea text = new JTextArea();
    text.setEditable(true);
    text.setText(gui.readFile("Persoane.txt"));
    text.getText();
    panel.add(text);

    getContentPane().add(panel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //setLocation(50,50);
setSize(300,200);
setResizable(false);
   // setVisible(true);
    show();
}


}
  • 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-04T01:35:11+00:00Added an answer on June 4, 2026 at 1:35 am
    1. Don’t to create a new JFrame, if you want the popup window use JDialog with parent of the frame.
    2. Don’t use show();, because this is long time depreciated method, remove that and un-commented // setVisible(true);
    3. Why two JButtons make the same things?
    4. Why using FileIO for passing value or argument from one Object to the other?
    5. I’d suggest to use CardLayout instead of to create a popup window.
    6. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); from class ShowDetails will close current JVM instance.
    7. Don’t extend JFrame or JDialog or JWindow
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a JFrame and want to hide this from the taskbar in
I have created a text field component with an 'x' button inside that will
I have created jframe in which jpanels are added dynamically what i can't do
I have created 2 classes as follows... public class A extends JFrame { public
I created a window using the design panel in JFrame, it didn't have any
I have created a file with XmlDocument xmldoc = new XmlDocument(); Can I make
I have created a JDialog to be opened when I click on the edit
I have created a JFrame form using netbeans GUI builder and place buttons on
I have created a simple JFrame with two labels, two fields and two buttons.
I have created a jframe using net beans and add combo box to 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.