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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:50:32+00:00 2026-06-08T02:50:32+00:00

I have created JAVA GUI that will receive text file(.txt) from other client and

  • 0

I have created JAVA GUI that will receive text file(.txt) from other client and append into the textarea(by using TextRecv.append) in Java Netbeans GUI however it doesn’t read file that already sent from other client , I try to put readfile method in button perform however it read only when I push the button but that’s not the result that I want, my target is make this GUI to dynamically receive file , read and append on to my text area automatically

My situation is I have 2 Machine and then I send file by execute dtncpd in Java that’s process how I send file over 2 machines however in both 2 machine the text file is already appear in destination but It not append in the textarea

That’s how I send

 private void DTNSendActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    String text = "";
    String name = usernameField.getText();
    text = name.toString()+ ":"+ TextInput.getText().toString();

    try{
        FileWriter fstream = new FileWriter("msg.txt");
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(text);
        out.close();
    }catch(IOException e)
    {
        e.printStackTrace();
    }
    TextInput.setText("");


    try{ //Show what sender type
        BufferedReader ins = new BufferedReader(new FileReader("msg.txt"));
        String Stream;
        while((Stream = ins.readLine())!=null)
        {
            TextRecv.append(Stream+"\n");
        }
    }catch(IOException e){ e.printStackTrace();}

    String sendcmd = "dtncp NetBeansProjects/DTNChat/msg.txt dtn://abc.dtn";
    Runtime runtime1 = Runtime.getRuntime();
    try{
        Process process1 =runtime1.exec(sendcmd);
    }catch(IOException e)
    {
        e.printStackTrace();
    }

The question is how can the Java Gui read the file that receive and append to the textarea automatically without using any button

Any Suggestion?? Thank you for every advice

Edited
I’m coding like this however it’s not append on my TextArea

 SwingWorker worker = new SwingWorker<Void,String>(){
    protected Void doInBackground(){
        File file = new File("/home/XXX/Desktop/incoming/ABC.dtn/msg.txt");
        boolean exists = file.exists();
        while(exists)
        {
            try{
                FileReader read = new FileReader("/home/XXX/Desktop/incoming/ABC.dtn/msg.txt");
                BufferedReader in = new BufferedReader(read);
                String show;
                while((show=in.readLine())!=null)
                {
                    TextRecv.append(show);
                }
            }catch(IOException e){}
        }
        return null;
    }
};

    public void actionPerformed(ActionEvent ae){
        worker.execute();
    }
  • 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-08T02:50:34+00:00Added an answer on June 8, 2026 at 2:50 am

    1. I am assuming that if there are 2 machines involved, then you must be sending and receiving on both sides.

    2. So you need to keep a separate thread, that will be running Out of your the EDT (Event Dispatcher Thread) which is your GUI thread.

    3. You can make this thread keep checking the Number of files in the particular folder where you are dropping the files, and keep a Count variable to keep the count. And Store the File Names in an ArrayList.

    4. When a new file arrives, the Count will increment by One, then check whether any file with this newly arrived file name is already in your ArrayList or not, if not append this file content to your JTextArea.

    5. Keep a separate thread to do the above, Not on the EDT, else your GUI will be non-responsive.

    ///////////////////////////////// EDITED: ////////////////////////////////////

    6. The main() method in Swing is Not Long Lived. It schedules the construction of GUI in the Event Dispactcher Thread and then quits. Now its the responsibility of the EDT to handle the GUI.

    7. Your main() method should only do the work of making the JFrame visible, using EventQueue.invokeLater.

    Eg:

        public static void main(String[] args){
    
           EventQueue.invokeLater(new Runnable(){
    
           public void run(){
    
           myFrame.setVisible(true);
         }
      }
    }
    

    8.SwingWorker is provided by Java to Synchronize the Work Output of the Non-UI thread on the GUI thread.

    /////////////////////EDITED//////////////////////////

    9. You can create a thread by extending to Thread Class or by Implementing Runnable.
    I am showing the example of Runnable here.

    Put these 2 classes in the same file.

    Class that implements Runnable

    class MyTest implements Runnable{
    
    public void run(){
    
       go();
    }
    
    public void go(){
    
      for (int i=0 ; i<10 ; i++){
    
               System.out.println("Hello i am work nos "+i);
        }
    
     }
    }
    

    Class that contains the main() method

    public class TestMain{
    
      public static void main(String[] args){
    
              Thread t = new Thread(new MyTest());
              t.start();
       }
    }
    

    10. You can also use Anonymous Inner class, that implements Runnable.

    Class with Anonymouse Inner class and main() method

        public class TestMain{
    
        public void go(){
    
               for(int i=0 ; i<10 ; i++){
    
                 System.out.println("Hello i am work nos "+i);
               }
    
       }
    
          public static void main(String[] args){
    
                  Thread t = new Thread(new Runnable(){
    
                  public void run(){
    
                    new TestMain().go();
    
               }
    
       });
                  t.start();
           }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a java application and packed it into a jar file on
I'm a Java beginner. I already created a simple GUI application that display will
I have a program with Driver GUI java file that creates a JFrame and
I have a working Java app that can find the most recently created file
I am trying to create a GUI using java swing. From there I have
I have created a java application for Debian Linux. Now I want that that
I have recently just created Java project using Eclipse that requires 2 JAR files
I have a simple Jython GUI that displays an XML file in a JTree.
I have a GUI window that I've created using Netbeans. I then ported the
I have created a fairly substantial Java GUI application with many form windows where

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.