Question

CREATE A JAVA GUI THAT SHOWS THE OUTPUT OF ANY JAVA FILE. FOR EXAMPLE IF THERE...

CREATE A JAVA GUI THAT SHOWS THE OUTPUT OF ANY JAVA FILE.
FOR EXAMPLE IF THERE IS A JAVA FILE THAT SIMPLY PRINTS "HELLO WORLD " OR ANY FILE THAT PRINTS TEXT AS OUTPUT .

CREATE A GUI THAT WILL ALLOW USER TO SELECT THE FILE AND RUN AND DISPLAY THE OUTPUT.   
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

public class FileChooserExample extends JFrame implements ActionListener {
   JButton open;
   JTextArea ta;

   FileChooserExample() {
       open = new JButton("Open File");
       open.addActionListener(this);
       open.setBounds(170, 0, 200, 20);
       ta = new JTextArea(800, 800);
       ta.setBounds(0, 20, 800, 800);
       add(open);
       add(ta);
   }

   public void actionPerformed(ActionEvent e) {
       if (e.getSource() == open) {
           JFileChooser fc = new JFileChooser();
           int i = fc.showOpenDialog(this);
           if (i == JFileChooser.APPROVE_OPTION) {
               File f = fc.getSelectedFile();
               String filepath = f.getPath();
               try {
                   BufferedReader br = new BufferedReader(new FileReader(filepath));
                   String s1 = "", s2 = "";
                   while ((s1 = br.readLine()) != null) {
                       s2 += s1 + "\n";
                   }
                   ta.setText(s2);
                   br.close();
               } catch (Exception ex) {
                   ex.printStackTrace();
               }
           }
       }
   }

   public static void main(String[] args) {
       FileChooserExample om = new FileChooserExample();
       om.setSize(500, 500);
       om.setLayout(null);
       om.setVisible(true);
       om.setDefaultCloseOperation(EXIT_ON_CLOSE);
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
CREATE A JAVA GUI THAT SHOWS THE OUTPUT OF ANY JAVA FILE. FOR EXAMPLE IF THERE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Following should be done in C++: Create a program that reads a text file and prints...

    Following should be done in C++: Create a program that reads a text file and prints out the contents of the file but with all letters converted to uppercase. The name of the file to be read by the program will be provided by the user. Here are some example session: Contents of "data.txt": Hello, World! User input: data.txt Program output: HELLO, WORLD! Contents of "data.txt": tHiS FiLe HaS mIxEd CaSeS User input: data.txt Program output: THIS FILE HAS MIXED...

  • In Java please Create a GUI application that accepts student registration data. The GUI with valid...

    In Java please Create a GUI application that accepts student registration data. The GUI with valid data Shudent Fagtrtion x Rt Name Haold Moore Lst Name Yar of Brth 2001 Temporary PesowordHal200 Wlcome Harald Moore! RegsterEt The GUI with invalid data Shudent Fegtrtion DX Fect Name Haold Last Name ar of Brth 2001 Tempoay Pawod Haold 200 Pesse eer St and lact name and ye of bith Regster Et Specifications Use FXML to create the GUI The text box that...

  • Java GUI Help! Hi, I have a Java GUI exercise that I need to complete and...

    Java GUI Help! Hi, I have a Java GUI exercise that I need to complete and was wondering if I could have a little bit of help... you can see it below. Create a simple graphical application that will enable a user to perform push, pop and peek operations on a stack and display the resulting stack (using toString) in a text area. Any help would be much appreciated! Thank you.

  • In Java, Create a program that can change any file (The file will be given by...

    In Java, Create a program that can change any file (The file will be given by the user) given to a byte array. Examples are: an image, audio file, etc (Can not be a text file!).

  • Write a Java program which takes a string as a user input. Create 2 functions. The...

    Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....

  • Need help on following Java GUI problem: Write a program that lets a user display and...

    Need help on following Java GUI problem: Write a program that lets a user display and modify pictures. Create a window. Add four buttons so that clicking a particular button will shift the image by a small amount in the north, south, east or west direction inside the window. Add a menu bar with two menus: File and Image. The File menu should contain an Open menu item that the user can select to display JPEG and PNG files from...

  • JAVA programming The task of parsing a file for correctness is an essential part of any...

    JAVA programming The task of parsing a file for correctness is an essential part of any programmer toolkit. The check for a balanced set of brackets in a file a Stack can be used and the following algorithm: • The source file is read character by character • Each time an opening '{' is read it is pushed onto the stack • Each time a closing '}' is read the stack is popped • If the stack is empty when...

  • Create a Java program that analyzes a program and produces the output into another file. The...

    Create a Java program that analyzes a program and produces the output into another file. The program must retrieve the path to the .java file. Once the path to the file is found the program must figure out the length of the longest line is in the program. For example, working with a program called MainFile.java. Once it figures out the longest line in the code it will put the output into MainFile.java.stats and it will be located in the...

  • In Java please, thank you! Design a GUI application as shown below and perform the following...

    In Java please, thank you! Design a GUI application as shown below and perform the following tasks: The text field is for data file name, the file extension must be.txt, otherwise, prompt user to provide a valid file name. Load the content of the data file and display on the textarea. 1. 2. Loading Files File Name: data.tt Load File

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT