-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
unknown, 1.1.4
-
x86, sparc
-
solaris_2.5.1
allan.jacobs@Eng 1997-10-21
The JCK test api/java_awt/interactive/descriptions.html#ColorTest
displays a pair of 4x4 color grid to the right of the window that it brings up.
The left member of the pair should be a darkened version of the right, but
it is not.
chrys.rowe@East 1997-11-17
The following happens only on intel using CDE
In the set of 4 squares that are supposed to be darker than the last set of 4 pink squares the lower right hand square is gray. All other squares are darkened correctly but this one square is just gray with no shade of pink at all. This is incorrect behavior. All othe platforms do not exhibit this behavior and darken the box correctly.
------------------------------------------------------------------------------
Following is a modified version of the JCK test, which shows more clearly that this is not a bug.
brian.klock@eng 1998-04-16
//-----------------------ColorTest.java------------------------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ColorTest extends Applet
{
final int NUM_COLORS = 6;
Panel pColors, pStatus;
Panel p, pButtons;
TextArea script;
ColorTriplet[] colors = new ColorTriplet[NUM_COLORS];
String scr = "This is an interactive test for class java.awt.Color.\n"
+ "Shown below are " + NUM_COLORS + " different columns of colors."
+ " In each column, the middle color is \n"
+ "the original color. The top color should be brighter than the "
+ "original color. The \n"
+ "bottom color should be darker than the original color.\n\n"
+ "Press the Darker button to make the darker row one step darker.\n"
+ "Press the Brighter button to make the brighter row one step "
+ "brighter. \nPress the Reset button to randomly generate the "
+ "original colors again.\n"
+ "To edit one of the colors, enter the (r,g,b) value in the "
+ "textfield and hit <Return>.\n";
public void init() {
setLayout(new GridLayout(3, 1, 20, 20));
script = new TextArea(scr);
add(script);
for (int i=0; i<NUM_COLORS; i++)
{
colors[i] = new ColorTriplet();
}
Button brighterB = new Button("Brighter");
brighterB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<NUM_COLORS; i++)
colors[i].brighter();
}
});
Button darkerB = new Button("Darker");
darkerB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<NUM_COLORS; i++)
colors[i].darker();
}
});
Button resetB = new Button("Reset");
resetB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<NUM_COLORS; i++)
colors[i].reset();
}
});
pColors = new Panel();
pColors.setLayout(new GridLayout(1, NUM_COLORS+1, 5, 5));
p = new Panel();
p.setLayout(new GridLayout(3,1,5,5));
p.add(brighterB);
p.add(resetB);
p.add(darkerB);
pColors.add(p);
for (int i=0; i<NUM_COLORS; i++)
{
pColors.add(colors[i]);
}
add(pColors);
pStatus = new Panel();
pStatus.setLayout(new GridLayout(1, NUM_COLORS+1, 5, 5));
pStatus.add(new Panel()); // dummy placeholder
for (int i=0; i<NUM_COLORS; i++)
{
pStatus.add(colors[i].getDisplayPanel());
}
add(pStatus);
}
/* Standalone interface */
public static void main(String args[])
{
Frame f = new Frame("ColorTest");
f.setSize(700,540);
ColorTest colorTest = new ColorTest();
colorTest.init();
colorTest.start();
f.add("Center", colorTest);
f.setVisible(true);
}
}
class ColorTriplet extends Panel implements ActionListener
{
Panel brighter, original, darker;
Panel displays;
Label brighterL, darkerL;
TextField originalT;
Random random;
public ColorTriplet()
{
setLayout(new GridLayout(3,1,5,5));
add(brighter = new Panel());
add(original = new Panel());
add(darker = new Panel());
displays = new Panel();
displays.setLayout(new GridLayout(3,1,5,5));
displays.add(brighterL = new Label());
displays.add(originalT = new TextField());
displays.add(darkerL = new Label());
originalT.addActionListener(this);
reset();
}
public void actionPerformed(ActionEvent e) {
String cText = originalT.getText();
int comma1 = cText.indexOf(",");
if (comma1>0) {
int comma2 = cText.indexOf(",", comma1+1);
if (comma2 > 0) {
String rStr = cText.substring(0, comma1);
String gStr = cText.substring(comma1+1, comma2);
String bStr = cText.substring(comma2+1);
int r = Integer.valueOf(rStr.trim()).intValue();
int g = Integer.valueOf(gStr.trim()).intValue();
int b = Integer.valueOf(bStr.trim()).intValue();
r = Math.max(0, Math.min(r, 255));
g = Math.max(0, Math.min(g, 255));
b = Math.max(0, Math.min(b, 255));
reset(new Color(r,g,b));
}
}
}
public void brighter() {
Color b = brighter.getBackground().brighter();
brighter.setBackground(b);
brighterL.setText(colorString(b));
}
public void darker() {
Color d = darker.getBackground().darker();
darker.setBackground(d);
darkerL.setText(colorString(d));
}
public void reset() {
reset(RandomColor());
}
public void reset(Color color) {
Color b = color.brighter();
Color d = color.darker();
brighter.setBackground(b);
original.setBackground(color);
darker.setBackground(d);
brighterL.setText(colorString(b));
originalT.setText(colorString(color));
darkerL.setText(colorString(d));
}
public Panel getDisplayPanel() {
return displays;
}
public Color RandomColor()
{
if (random == null)
random = new java.util.Random();
return new Color(
Math.abs(random.nextInt()) % 255,
Math.abs(random.nextInt()) % 255,
Math.abs(random.nextInt()) % 255);
}
public String colorString(Color c)
{
int r, g, b;
r = c.getRed();
g = c.getGreen();
b = c.getBlue();
return new String("" + r + "," + g + "," + b);
}
}
//---------------------------------------------------------------------