Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I have to create a gui that has 7 buttons, I have the gui created, but writing the action listners for each button is

Hello,

I have to create a gui that has 7 buttons, I have the gui created, but writing the action listners for each button is where I am stuck. Button 1: Complete event - handler for button Load text from file inputText.txt. Click on this button will load the content of given text file inputText.txt to the left JTextArea (the right one should be cleared). The text file will be loaded as a file upload. Button 2: Complete event - handler for button Write the selected text to file outputText.txt. Click on this button will output the selected text to file outputText.txt and this file should be in the same folder as your Java program. Button 3: Complete event - handler for button Convert Date Format. Click on this button will convert the selected dates from the left JTextArea to the format shown in the right JTextArea. Button 4: Complete event - handler for buttonLetter Count. Click on this button will print a table in the right JTextArea the number of occurrences of each different letter in the selected text in the left JTextArea. The left column of the table is a list of 26 letters (upper case) and the right column shows the corresponding occurrences. You may first convert the selected text to upper cases and then complete the counting. Button 5: Complete event - handler for button Word Count. Click on this button will print a table in the right JTextArea the number of occurrences of words having different lengths in the selected text in the left JTextArea. The left column of the table is a list of word lengths (from 0 to 20) and the right column shows the corresponding occurrences. Button 6: Complete event - handler for button Write objects to file outputObj.ser. You will need first create 4 different objects from the 4 given classes: BasePlusCommissionEmployee, CommissionEmployee.java, HourlyEmployee, and SalariedEmployee. You may use the following screenshot example to set up the initial values for these objects. Then you will need to output these objects in file outputObj.ser in the same folder as the Java program. The left JTextArea should be clear. Button 7: Complete event - handler for button Load objects from file outputObj.ser. Click on this button will read the objects saved in file outputObj.ser and print them in the left JTextArea. Also each objects class name should be printed based on the operation on the objects at the end! You must obtain information about the objects from the saved objects rather than the initial values used to create these objects!

The gui has two text boxes on the right and left, and the middle panel is where the buttons are.

The sample code that was given is as follows:

// Fig. 12.48: TextAreaDemo.java

// Testing TextAreaFrame.

import javax.swing.JFrame;

public class TextAreaDemo

{

public static void main(String[] args)

{

TextAreaFrame textAreaFrame = new TextAreaFrame();

textAreaFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

textAreaFrame.setSize(425, 200);

textAreaFrame.setVisible(true);

}

} //

// Fig. 12.47: TextAreaFrame.java

// Copying selected text from one textarea to another.

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.Box;

import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JButton;

import javax.swing.JScrollPane;

public class TextAreaFrame extends JFrame

{

private final JTextArea textArea1; // displays demo string

private final JTextArea textArea2; // highlighted text is copied here

private final JButton copyJButton; // initiates copying of text

// no-argument constructor

public TextAreaFrame()

{

super("TextArea Demo");

Box box = Box.createHorizontalBox(); // create box

String demo = "This is a demo string to " +

"illustrate copying text from one textarea to " +

"another textarea using an external event ";

textArea1 = new JTextArea(demo, 10, 15);

box.add(new JScrollPane(textArea1)); // add scrollpane

copyJButton = new JButton("Copy >>>");

box.add(copyJButton); // add copy button to box

copyJButton.addActionListener(

new ActionListener() // anonymous inner class

{

// set text in textArea2 to selected text from textArea1

@Override

public void actionPerformed(ActionEvent event)

{

textArea2.setText(textArea1.getSelectedText());

}

} // end anonymous inner class

); // end call to addActionListener

textArea2 = new JTextArea(10, 15);

textArea2.setEditable(false);

box.add(new JScrollPane(textArea2)); // add scrollpane

add(box); // add box to frame

} // end TextAreaFrame constructor

} // end class TextAreaFrame

Any help would be fantastic. Thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

Understand why unit costs must be interpreted with caution .

Answered: 1 week ago

Question

Compose the six common types of social business messages.

Answered: 1 week ago

Question

Describe positive and neutral messages.

Answered: 1 week ago