Question
StringSet Yet Again Attached Files: StringSetGuiFrames.zip (86.121 KB) In several labs we've written classes that stored and analyzed String objects. The Inheritance lesson had StringSet
StringSet Yet Again
Attached Files:
StringSetGuiFrames.zip (86.121 KB)
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
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. Note: the same event handler that handles button pushes can, with no modification, handle the enter> 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.
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