Question: Do in Java. Use Inheritance and Interfaces on one class you write to create a window that when clicked on swaps colors of the window.
Do in Java.
Use Inheritance and Interfaces on one class you write to create a window that when clicked on swaps colors of the window.
Create a new project called MyInheritanceFrame.
Have your class inherit from JFrame (import the proper libraries).
In public static main create an instance of your class (your class that is inheriting from JFrame)
Send in a String to the constructor of your class and then pass it on to JFrame so when the frame is shown it has the String as the title "232 Frame" (like in my images below).
Set the size of the frame to 300, 600 (inherited method) in your constructor.
Add this line in your constructor: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
create a JPanel -- "new JPanel()" this JPanel should be an instance field so you can change it later.
Set the background color of the panel to yellow
You need to find out how to set the color and create a new instance of the Color class with 255, 255, 0
add the panel to the contentPane of your frame -- getContentPane().add(
this will give you the contentPane and the first part of the add method, add it using default layout....which means you just have to add it, nothing else.
In your constructor make the frame visible calling the method you inherited that will make it visible.
Run your program and you should see something exactly like this:

Now we will add a MouseListener to the code.
Add a MouseListener interface to your class that inherits from JFrame
Include all the methods needed to get this to compile.
Since MouseListener is an interface you have to include all the methods it's requiring, look them up, they can be {} = blank, but they have to be there.
In the mouseReleased method add code to change the background color from yellow to a new color, and use random generated colors, RGB colors 0-255 randomly generated. Each time you click it should change colors.
new Color(red, gree, blue)
red, green and blue are Random generated numbers 0-255
When the mouse leaves the frame it should always go back to yellow, different interface method
Here are screen captures of my window showing the result after three clicks and then the mouse exiting.

232 Lab
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
