Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Changing the order of Color Alternation Question 2. The ColorPanel program allows you to change a panel's background color from red to blue, blue

1. Changing the order of Color Alternation Question 2. The ColorPanel program allows you to change a panel's background color from red to blue, blue to green, green to red and so forth in a repeating cycle. Download the program from the link provided below and run it on your local machine to see it in action. /JavaTutor/src/guibasics/reversecolor/ColorPanel.java Now modify this program so that clicking changes the colors in the opposite direction: red -> green -> blue -> red, from red to green, and so on. [note: we've provided the original code in the answer box.] You can see the correct result by clicking on the Color Panel link below: Color Panel

image text in transcribed Assignment: 12.5 Exercises image text in transcribed Due Date: 7/16/2018 11:59 PM
image text in transcribedQuestion Score: 0.0 of 2.0 Send Message

image text in transcribed

Question: 12.5.2

Close Window

Score: Sorry, you did not answer the question correctly. Answer(s): (Your response(s) are shown below.)

1. Changing the order of Color Alternation

Question 2. The ColorPanel program allows you to change a panel's background color from red to blue, blue to green, green to red and so forth in a repeating cycle. Download the program from the link provided below and run it on your local machine to see it in action. /JavaTutor/src/guibasics/reversecolor/ColorPanel.java Now modify this program so that clicking changes the colors in the opposite direction: red -> green -> blue -> red, from red to green, and so on. [note: we've provided the original code in the answer box.] You can see the correct result by clicking on the Color Panel link below: Color Panel import javax.swing.*; import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class ColorPanel extends JPanel implements ActionListener { public static final String RED = "red"; public static final String BLUE = "blue"; public static final String GREEN = "green"; public String currentColor; JButton changeColorButton; public ColorPanel() { changeColorButton = new JButton("Change Color"); this.add(changeColorButton); changeColorButton.addActionListener(this); this.setBackground(Color.red); this.currentColor = RED; this.setPreferredSize(new Dimension(400, 200)); } public void actionPerformed(ActionEvent e) {
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
if(currentColor.equals(RED))
{
 setBackground(Color.blue);
 currentColor = BLUE;
}
else if(currentColor.equals(BLUE))
{
 setBackground(Color.green);
 currentColor = GREEN;
}
else if(currentColor.equals(GREEN))
{
 setBackground(Color.red);
 currentColor = RED;
}
} public static void main(String[] args) { JFrame frame = new JFrame("My Color Panel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ColorPanel newPanel = new ColorPanel(); frame.setContentPane(newPanel); frame.pack(); frame.setVisible(true); }// end main }// end class

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

LO1 Discuss four different views of motivation at work.

Answered: 1 week ago

Question

LO6 Summarize various ways to manage retention.

Answered: 1 week ago