Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In several labs we've written classes that stored and analyzed String objects. The Inheritance lesson had StringSet Revisited and Writing Classes Better had the original
In several labs we've written classes that stored and analyzed String objects. The Inheritance lesson had StringSet Revisited and Writing Classes Better had the original StringSet. Use one of these previously written classes in this program (it doesn't really matter which--they do the same thing).
Write a WidgetView application. Create a class StringAnalysis.
This class has an event handler inner class extending WidgetViewActionEvent
It has instance variables
StringSet sSet
JTextField inputStr
JLabel numStr
JLabel numChar
JTextArea listOfStrings
In the constructor,
create a WidgetView object
create sSet
create a local variable JLabel prompt initialized to "Enter a String"
create inputStr with some number of columns
create a local variable JButton pushMe initialized to "Push to include String"
create numStr initialized to "Number of Strings: 0"
create numChar initalized to "Number of Characters: 0"
create an event handler object and add it as a listener to pushMe
add prompt, inputStr, pushMe, numStr and numChar to your WidgetView object.
Your event handler should add inputStr's contents to sSet and set inputStr to "". It should update numStr and numChar labels to contain sSet's current information. listOfStrings should be updated to show the entered strings.
Test data and a suggested layout can be found in Unit 13 Lab Grade Sheet Key.
Note: the same event handler that handles button pushes can, with no modification, handle the key for a JTextField. For the adventurous, use inputStr's addActionEvent method to add your event handler. (You can use the same object you added to pushMe--you don't even have to create a new one). Then run your program, enter text in the inputStr field, and press the enter key.
Note 2: In the Writing Classes lesson, the Anatomy of a Java Program item said "...we often want to use the business logic in multiple contexts. We might want a text-based application.... We might want to also use it in a graphical user interface (GUI), and we'll write things like that before the course is over." We've just made good on that promise. The StringSet class (no matter which incarnation of StringSet you
choose to use) was written as part of a text application. We've now incorporated it into a GUI application with no changes at all. In fact, if our development environment was sophisticated enough, we wouldn't even recompile it. Our GUI app picked up the StringSet class for free.
This is the code Stringset and a tester I used it last time
Below is the output of the program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started