Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1) Recreate the Affirmation Application presented on slides 59-74 of Java Swing Basics. The given application is composed of three classes a) Affirm on slides
1) Recreate the "Affirmation Application" presented on slides 59-74 of "Java Swing Basics". The given application is composed of three classes a) Affirm on slides 64-65 b) AffirmComponent on slides 66-68 c) AffirmFrame on slides 69-74 ***Do not forget the package imports: awt, swing, event and java.util.ArrayList 2) Add Color: Each Affirm must have a fixed color. The color is randomly generated when the Affirm object is constructed, then it is stored in myColor, along with the corresponding myString, myX and myY. This color must be used whenever this Affirm object is displayed. For example, two different instances of the "Lookin' good" Affirm objects might be created. The first Affirm object will have a random color C1 assigned to it at the time it was created. Similarly the second Affirm object will have a random color C2 that will be assigned to it at the time it was created. Both of the Affirm objects will move randomly, but the first will always be displayed in color C1 while the second will always be displayed with color C2 To generate a random color, you need to generate three integers corresponding to the red, green and blue components of color. Each of the three color componenets is between 0 and 255. Then, use the Color (R, G, B) constructor (See the first screen shot on the next page.) 3) Add a Center JButton between the Remove and Start buttons. The action associated with this button is to reset the myX and myY coordinates of all the Affirm objects to the center of the window; i.e. middle of getWidth() and getHeight( ). This way, all Affirm objects are repositioned in the middle of the window for a brief moment, then the Affirm objects resume to randomly move in all directions Note that the reference point for strings displaved using g.drawStringis the lower left corner of the string, i.e. the left end of the baseline. This is in contrast with all other graphical objects that have a bounding rectangle and where the upper left corner is used as their origin. The reason for this exception should be obvious (See the second screen shot on the next page.)
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