Question: A . Write the GUI with a textfield and implement the code so that the user can type into the textfield and see the text

A. Write the GUI with a textfield and implement the code so that the user can type into the
textfield and see the text they typed in printed on the command prompt.
B. The user is supposed to be typing in a file name such as matrix1.txt. Now modify
your code so that the text the user typed in is used as the filename that is opened. Open
the file and read in the data (number of rows, number of columns, and the two integer
matrices). This code can be copy pasted (with a few small modifications) from the
previous lab.
C. Pass the two matrices to the Server and write the server so that it displaysthe matrices
on its end (either through a Server GUI or on the Server-side command prompt).
DO NOT perform any matrix calculations on the Server side yet. Dont create threads or sum
quadrants or calculate indexes. I want to make sure Part 1 is completed successfully before
you move on.
Instructions for P
USING
// Ask user to enter the matrix file
//*** not covered:
// Perform the multi-thread computation and gather the result
// Display the result on the JScrollPane
// Demo: Display the content of the matrix from the file opened by the previous step
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class ReadWriteData extends JFrame
{
private JTextField enterField; // JTextField to enter the matrix file name
private JTextArea displayArea; // JTextAreato display the computation result
private File file;
private Scanner input;
// set up GUI
public ReadWriteData()
{
super("Open File and Output Data Example");
// create enterField and register its listener
enterField = new JTextField("Enter file name here");
add(enterField, BorderLayout.NORTH);
displayArea = new JTextArea();
add(new JScrollPane(displayArea), BorderLayout.CENTER);
enterField.addActionListener(
new ActionListener(){
// get the file name specified by user
public void actionPerformed(ActionEvent event){
getFile(event.getActionCommand());
}
}
);
setSize(400,300); // set size of window
setVisible(true); // show window
}
// load document
private void getFile(String file_name)
{
file = new File(file_name);
try {
input = new Scanner(file);
} catch (FileNotFoundException e){
System.out.printf("%nError on file: %s (either enpty or wrong file format)%n%n", file);
e.printStackTrace();
System.exit(1);
}
String s;
while (input.hasNextLine()){
s = input.nextLine();
displayArea.append(s +"
");
}
}
}
AND THIS
// Create and start a ReadWriteData object.
import javax.swing.JFrame;
public class ReadWriteDataTest
{
public static void main(String[] args)
{
ReadWriteData application = new ReadWriteData();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!