Question: Modify the following exercise 7-2 on comparing strings so it is now done in a GUI application frame class definition with a main instead of

Modify the following exercise 7-2 on comparing strings so it is now done in a GUI application frame class definition with a main instead of a console application. The GUI components will be data fields of the class definition. The prompts will now be in labels and the input will now betextfields. The user will hit enter in the second textfield to get the results in two other answer labels. The results (which is greater and the difference amount) will be in these two other answer labels. Declare everything at the top, use the constructor to add the components to your container (use background and foreground colors and the flow layout), and use actionPerformed to do three things: get the text out of the textfields for the two strings (instead of readLines), to perform the nested if else with the comparisons, and the setting of the answers in the two answer labels - which is greater and the difference (instead of printlns). Use a little main method to construct yourself. Take a picture of the output GUI frame with which will copy the frame, paste into paint, and save as a .jpg file. Attach the . java program file .jpg output file and submit.

ex7-2

import java.io.*; public class ex72a { public static void main(String[] args) throws IOException { String s1, s2; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a string: "); s1 = br.readLine(); System.out.print("Enter a string: "); s2 = br.readLine(); if (s1.equals(s2)) // (s1 == s2) System.out.println("Same string"); else if (s1.equalsIgnoreCase(s2)) System.out.println("Same string - different case"); else if (s1.compareTo(s2) > 0) // s1 > s2 System.out.println(s1 + " is greater than " + s2); else // s1 < s2 System.out.println(s1 + " is less than " + s2); System.out.println("Difference is " + s1.compareTo(s2)); } }

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 Databases Questions!