Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java programming language. Write a program that displays a frame with the following GUI elements: - a label that displays a simple icon with a

Java programming language. Write a program that displays a frame with the following GUI elements: - a label that displays a simple icon with a circle initially colored solid red - a button labeled "Green" - a button labeled "Blue" - a button labeled "Red" When the user clicks a button, the circle color must change to that indicated by the button's label. Implementation requirements: i) when a button is clicked you need to change the icon's color, then call the label's repaint() method. This, in turn will call the icon's paintIcon() method, so that the icon is redrawn with the new color. In other words, you don't call paintIcon() directly, the JLabel object does it. ii) the buttons' action listener objects must be of anonymous classes. iii) the buttons must be created in main() and set up in a loop with loop index from 0 to 2, like this: for (i=0; i<3; i++) { btn[i] = createButton(i, ......); } The createButton() function you will write gets an index (0 to 2) and creates the green, blue, and red buttons, depending on the valus of i. JButton objects are returned with the proper listener attached. Hint: Use a Color array that can be indexed by i: Color[] colors = new String[]{"RED", "GREEN", "BLUE"}; Then, create the color with the required color: final Color c = colors[i]; Remember, you can only refer to "final" local variables from the outside scope and to instance variables inside anonymous class functions.

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

More Books

Students also viewed these Databases questions

Question

What is the general purpose of preliminary screening?

Answered: 1 week ago