Newby Java Question

lederhosen

Member
Apr 23, 2005
172
0
0
Ok so the premise is this: I need to write a java program that constructs a color object with values of 50, 100 and 150. Then I need to apply the brighten method and print the results. This is what I have so far:

import java.awt.Color;

public class BrightenTester
{
public static void main(String[]args)
{
new Color (50,100,150);
Color brighter;
}
}

I know it's messed up, I just don't know how to get it to print the new values. Any help?
 

wkinney

Senior member
Dec 10, 2004
268
0
0
Firstly you need to store the newly created Color object, right now it is being created, but it is not being stored. you need:

Color myColor = new Color (50,100,150);

brighter is a method of the object Color, in this case 'myColor'. To reference an object's method, you need to use the . operator, e.g.
myColor.brighter();
 

lederhosen

Member
Apr 23, 2005
172
0
0
Thank you. Then I went to print the resulting color by doing System.out.println(myColor); but what I got was the original values (50,100,150). Any ideas?
 

Thyme

Platinum Member
Nov 30, 2000
2,330
0
0
I'll give you the answer, but you should be able to figure this out using the API or else I reccomend gettnig a better understanding of Java OOP.

import java.awt.Color;

public class BrightenTester
{
public static void main(String[]args)
{
Color myColor = new Color (50,100,150);
Color brighterColor = myColor.brighter();
System.out.println(brighterColor);
}
}