選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ColorLabel.java 1023B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. */
  10. package observer;
  11. import java.awt.Color;
  12. import java.awt.Label;
  13. class ColorLabel extends Label {
  14. ColorLabel(Display display) {
  15. super();
  16. display.addToFrame(this);
  17. }
  18. final static Color[] colors = {Color.red, Color.blue,
  19. Color.green, Color.magenta};
  20. private int colorIndex = 0;
  21. private int cycleCount = 0;
  22. void colorCycle() {
  23. cycleCount++;
  24. colorIndex = (colorIndex + 1) % colors.length;
  25. setBackground(colors[colorIndex]);
  26. setText("" + cycleCount);
  27. }
  28. }