Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30397
| From | Knute Johnson <eternal@knutejohnson.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Could this be done better |
| Date | 2014-11-24 09:41 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <m4vqju$fnv$1@dont-email.me> (permalink) |
| References | <87zjbg97c5.fsf@Equus.decebal.nl> <m4vf1f$j03$1@dont-email.me> <m4vpb5$9ue$1@dont-email.me> |
// private classes
private class Colour {
// public
public Colour(Color color, String description) {
this.color = color;
this.description = description;
}
public Color getColor() {
return color;
}
public String getDescription() {
return description;
}
// private
private Color color;
private String description;
}
private class SwitchColour extends TimerTask {
public void run() {
updateColour(getNextColour());
}
}
//private functions
private Colour getCurrentColour() {
return colours[currentColour];
}
private Colour getNextColour() {
currentColour = (currentColour + 1) % colours.length;
return getCurrentColour();
}
As much as I like your class Colour, it is probably easier and simpler
to use an enum in this case.
import java.awt.*;
public class test {
enum Colours {
Red(Color.RED),Blue(Color.BLUE),Green(Color.GREEN);
private final Color value;
Colours(Color value) {
this.value = value;
}
public Color value() {
return value;
}
}
public static void main(String... args) {
System.out.println(Colours.Red);
System.out.println(Colours.Red.value());
System.out.println();
for (Colours colour : Colours.values())
System.out.println(colour+":"+colour.value());
}
}
C:\Users\Knute Johnson>java test
Red
java.awt.Color[r=255,g=0,b=0]
Red:java.awt.Color[r=255,g=0,b=0]
Blue:java.awt.Color[r=0,g=0,b=255]
Green:java.awt.Color[r=0,g=255,b=0]
--
Knute Johnson
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 12:16 +0100
Re: Could this be done better "Qu0ll" <Qu0llSixFour@gmail.com> - 2014-11-24 22:49 +1100
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 17:54 +0100
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 09:37 -0800
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 19:27 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-24 09:23 -0500
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 17:45 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-24 13:42 -0500
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-25 00:12 +0100
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 09:19 -0800
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 09:41 -0800
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-25 00:55 +0100
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-25 00:11 +0100
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 16:26 -0800
Re: Could this be done better Brixomatic <brixomatic@yahoo.com> - 2014-11-25 19:58 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-25 14:36 -0500
Re: Could this be done better Brixomatic <brixomatic@yahoo.com> - 2014-11-26 01:58 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-26 08:48 -0500
Re: Could this be done better Brixomatic <brixomatic@yahoo.com> - 2014-11-29 19:43 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-29 15:44 -0500
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-29 15:47 -0500
csiph-web