Reputation: 13
I cannot seem to figure out what I am doing wrong. Here is the exercise in the textbook:
"In the Java library, a color is specified by its red, green, and blue components between 0 and 255 (see Table 4 on page 68). Write a program BrighterDemo that con- structs a Color object with red, green, and blue values of 50, 100, and 150. Then apply the brighter method of the Color class and print the red, green, and blue values of the resulting color"
Here's the code I have so far:
import java.awt.Color;
import javax.swing.JFrame;
public class BrighterDemo
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(200, 200);
Color myColor = new Color(50, 100, 150);
Color brighterRedColor = myColor.red.brighter();
Color brighterGreenColor = myColor.green.brighter();
Color brighterBlueColor = myColor.blue.brighter();
frame.getContentPane().setBackground(myColor);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
EDIT: I figured it out, here's the correct code:
import java.awt.Color;
public class BrighterDemo
{
public static void main(String[] args)
{
Color myColor = new Color(50, 100, 150);
Color brighterColor = myColor.brighter();
System.out.println("Red - ");
System.out.println(brighterColor.getRed());
System.out.println("Green - ");
System.out.println(brighterColor.getGreen());
System.out.println("Blue - ");
System.out.println(brighterColor.getBlue());
}
}
Upvotes: 0
Views: 2361
Reputation: 16225
There's a few things not quite right with your code:
brighterRedColor, brighterGreenColor, brighterBlueColor
, but not doing anything with them (such as printing them out)Color.red, Color.green, Color.blue
instances, not your myColor
object.myColor
and output them after you apply brighter()
to your color. Not to create 3 new colors and brighten them.Upvotes: 1