Question: Swing Application Introduction In Assignment 1 you created a few methods to manipulate a 3-digit number. In this assignment you are going to create a

Swing Application

Introduction

In Assignment 1 you created a few methods to manipulate a 3-digit number. In this assignment you are going to create a user interface for it. The interface should be in the form of an application that is extended from JFrame. In addition you are going to add the ability to change the text color of the values being output. Your interface should look like this:

Swing Application Introduction In Assignment 1 you created a few methods to

You need to make your interface match the one above as close as possible. The components on the interface were placed using the SpringLayout. You are required to use the SpringLayout to position the components for your program

Specifics

Methods You need to output the sum of the three numbers, the reverse, and each value of the array. All of these values should be derived by calling three separate methods taken from Assignment 1:

sumNums - This method takes as input a three digit int and returns the sum of the three numbers. For instance, 123 would return 6 because 3 + 2 + 1 is 6

reverseNums - This method takes as input a three digit int and returns the number in reverse as a String. For instance, 123 would return "321"

getArray - This method takes as an argument a three digit number and returns the numbers as an int array. Each element of the array should contain one of the numbers

Events - You also must create two inner classes to handle the events. One of the inner classes will handle the radio buttons the other will handle the compute button. The event for the radio button should change the foreground color of all of the output fields.

Constructors - You are required to have one default constructor and one working constructor that takes the title, width, and height. You should create an instance of Lab2 in main using the working constructor.

The Spring Layout

The SpringLayout allows you to attach springs to components to adjust their position relative to the content pane or other components. To use the SpringLayout you need to set the layout of the content pane to a SpringLayout:

SpringLayout layout = new SpringLayout(); content.addLayout(layout);

Once you have setup a SpringLayout you use constraints on your components to set their positions. Before getting to that there are some constants that should be discussed. These are all members of the SpringLayout class:

SpringLayout.NORTH Specifies the top edge of a component
SpringLayout.SOUTH Specifies the bottom edge of a component
SpringLayout.EAST Specifies the right edge of a component
SpringLayout.WEST Specifies the left edge of a component

Once you have added a component to the content pane you can then use the putConstraint method that is part of the layout to place the component:

manipulate a 3-digit number. In this assignment you are going to create

The first putConstraint says place the left edge (WEST) of lblName 15 pixels from the left (WEST) edge of the content pane;

The second putConstraint says position the top edge (NORTH) of lbName 30 pixels from the top edge (NORTH) of the content pane.

Please note that you need to put two constraints per component. One to position the vertical and one to position the horizontal. Here is how this constraint looks:

a user interface for it. The interface should be in the form

When you have multiple components you will probably need to place them relative to other components. Here is adding a second label below the name:

of an application that is extended from JFrame. In addition you are

hee first constraint is really positions the horizontal position the same as constraint in the Name label. The last constraint says position the top edge (NORTH) of lblAddress 20 pixels from the bottom edge (SOUTH) of lblName. Here is what that the whole thing looks like:

going to add the ability to change the text color of the

Something To Consider

Do not think that placing the components with the SpringLayout is a trivial thing. It takes a little while to get the hang of it so give yourself plenty of time.

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!