Name: sg39081 Date: 10/22/97
The brighter() method in the java.awt.Color class
does not work under certain conditions. For example
if I have chosen the color to be blue: RGB=(0,0,255)
it does not return a brighter version of the color.
In the source code, a new instance of Color is
returned which has the original color's RGB values
multiplied by a certain factor, but what if one of
the RGB values is 0, which mutliplied is still 0!
So a brighter version of pure blue is pure blue if
you execute the method... But aren't you supposed to
have a "lighter blue" as the brighter version...
------------
Or: Color.black.brighter() will not return a shade
of gray but pure black!
------------
Or maybe I'm confusing the technical definition of
brighter???
import java.awt.*;
import java.awt.event.*;
public class b
{
Frame f;
ColorComponent c1;
Button b1;
b(Color c)
{
f = new Frame();
c1 = new ColorComponent(c);
b1 = new Button("Brighter");
f.add("North", c1);
c1.addMouseListener(c1);
b1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
Color new_c = c1.myColor.brighter();
System.out.println("New color=(" +
new_c.getRed() + "," +
new_c.getGreen() + "," +
new_c.getBlue() + ")"
);
c1.setColor(new_c);
c1.paint(c1.getGraphics());
}
}
);
f.add("South", b1);
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
b my_b;
float r, g, b;
if (args.length ==3)
{
r = new Float(args[0]).floatValue();
g = new Float(args[1]).floatValue();
b = new Float(args[2]).floatValue();
my_b = new b(new Color(r/255.0f, g/255.0f, b/255.0f));
}
else
my_b = new b(new Color(0,100,100));
}
}
class ColorComponent extends Component implements MouseListener
{
public ColorComponent() { }
public ColorComponent(Color c)
{
myColor = c;
}
public Dimension getPreferredSize()
{
return new Dimension(100,100);
}
public void paint(Graphics g)
{
g.setColor(myColor);
g.fillRect(0,0,100,100);
}
public void setColor(Color c)
{
myColor = c;
}
public void mouseClicked(MouseEvent me)
{
if (myColor.equals(Color.red))
System.out.println("Red");
else
System.out.println("Blue");
}
public void mouseEntered(MouseEvent me) { }
public void mouseExited(MouseEvent me) { }
public void mousePressed(MouseEvent me) { }
public void mouseReleased(MouseEvent me) { }
public Color myColor = Color.black;
}
======================================================================