リビジョン 4838a05f
| AnalogClockDrawing/src/analogclock/AnalogClockDrawing.java | ||
|---|---|---|
|
*/
|
||
|
public class AnalogClockDrawing extends Application {
|
||
|
|
||
|
private static double UNIT_SIZE = 100d;
|
||
|
private static final double UNIT_SIZE = 100d;
|
||
|
private Rotate secondsHandRotation;
|
||
|
private Rotate minuteHandRotation;
|
||
|
private Rotate hourHandRotation;
|
||
| ... | ... | |
|
public void start(Stage primaryStage) {
|
||
|
|
||
|
Group root = new Group();
|
||
|
Node secondsHand = createSecondsHand();
|
||
|
Node tickMarks = createTickMarks();
|
||
|
root.getChildren().addAll(
|
||
|
createDial(),
|
||
|
createMinuteHand(),
|
||
|
createHourHand(),
|
||
|
secondsHand,
|
||
|
tickMarks,
|
||
|
createSecondsHand(),
|
||
|
createTickMarks(),
|
||
|
createCenter()
|
||
|
);
|
||
|
|
||
| ... | ... | |
|
// 時計の短針を作成する
|
||
|
Node createHourHand() {
|
||
|
hourHandRotation = new Rotate(0, UNIT_SIZE, UNIT_SIZE);
|
||
|
Node hourHand = createHourOrMinuteHand(UNIT_SIZE * 0.4, Color.BLACK, 0);
|
||
|
Node hourHand = createHourOrMinuteHand(UNIT_SIZE * 0.4, Color.BLACK);
|
||
|
hourHand.getTransforms().add(hourHandRotation);
|
||
|
return hourHand;
|
||
|
}
|
||
| ... | ... | |
|
// 時計の長針を作成する
|
||
|
Node createMinuteHand() {
|
||
|
minuteHandRotation = new Rotate(0, UNIT_SIZE, UNIT_SIZE);
|
||
|
Node minuteHand = createHourOrMinuteHand(UNIT_SIZE * 0.2, Color.BLACK, 0);
|
||
|
Node minuteHand = createHourOrMinuteHand(UNIT_SIZE * 0.2, Color.BLACK);
|
||
|
minuteHand.getTransforms().add(minuteHandRotation);
|
||
|
return minuteHand;
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
|
||
|
// 時計の針を作成する
|
||
|
Node createHourOrMinuteHand(double stretchRelativeToRim, Color color, int startAngle) {
|
||
|
Node createHourOrMinuteHand(double stretchRelativeToRim, Color color) {
|
||
|
Path path = new Path(
|
||
|
new MoveTo(UNIT_SIZE, UNIT_SIZE),
|
||
|
new LineTo(UNIT_SIZE * 0.9, UNIT_SIZE * 0.9),
|
||
| ... | ... | |
|
);
|
||
|
path.setFill(color);
|
||
|
path.setStroke(Color.TRANSPARENT);
|
||
|
path.getTransforms().add(new Rotate(startAngle, UNIT_SIZE, UNIT_SIZE));
|
||
|
return path;
|
||
|
}
|
||
|
|
||
コードの書きっぷりを揃える、定数のfinal宣言漏れ対処