Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

=+4 What are non-union workers representations?

Answered: 1 week ago