mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added analog clock V
This commit is contained in:
parent
c0003ae5e8
commit
e73d0d75ab
@ -19,6 +19,12 @@ public class AnalogClock extends JPanel {
|
|||||||
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||||
private static final Color BACKGROUND_COLOR = new Color(238,238,238);
|
private static final Color BACKGROUND_COLOR = new Color(238,238,238);
|
||||||
|
|
||||||
|
private boolean highlight = false;
|
||||||
|
|
||||||
|
public void setHighlight(boolean highlight) {
|
||||||
|
this.highlight = highlight;
|
||||||
|
}
|
||||||
|
|
||||||
public AnalogClock() {
|
public AnalogClock() {
|
||||||
setPreferredSize(new Dimension(400, 300));
|
setPreferredSize(new Dimension(400, 300));
|
||||||
setBackground(BACKGROUND_COLOR);
|
setBackground(BACKGROUND_COLOR);
|
||||||
@ -56,7 +62,7 @@ public class AnalogClock extends JPanel {
|
|||||||
int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
|
int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
|
||||||
int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
|
int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
|
||||||
|
|
||||||
g2d.setColor(FOREGROUND_COLOR);
|
g2d.setColor(highlight ? Color.BLUE : FOREGROUND_COLOR);
|
||||||
g2d.setStroke(new BasicStroke(stroke));
|
g2d.setStroke(new BasicStroke(stroke));
|
||||||
g2d.drawLine(getWidth() / 2, getHeight() / 2, endX, endY);
|
g2d.drawLine(getWidth() / 2, getHeight() / 2, endX, endY);
|
||||||
}
|
}
|
||||||
@ -64,7 +70,7 @@ public class AnalogClock extends JPanel {
|
|||||||
private void drawClockFace(Graphics2D g2d, int centerX, int centerY,
|
private void drawClockFace(Graphics2D g2d, int centerX, int centerY,
|
||||||
int radius) {
|
int radius) {
|
||||||
g2d.setStroke(new BasicStroke(2.0f));
|
g2d.setStroke(new BasicStroke(2.0f));
|
||||||
g2d.setColor(FOREGROUND_COLOR);
|
g2d.setColor(highlight ? Color.BLUE : FOREGROUND_COLOR);
|
||||||
System.out.println("centerX=" + centerX);
|
System.out.println("centerX=" + centerX);
|
||||||
System.out.println("centerY=" + centerY);
|
System.out.println("centerY=" + centerY);
|
||||||
System.out.println("radius=" + radius);
|
System.out.println("radius=" + radius);
|
||||||
|
@ -146,6 +146,11 @@ public class TimeCalc {
|
|||||||
if(hourRemains == 0 && minuteRemains ==1) {
|
if(hourRemains == 0 && minuteRemains ==1) {
|
||||||
Vtipy.showRandom();
|
Vtipy.showRandom();
|
||||||
}
|
}
|
||||||
|
if(hourRemains == 0 && minuteRemains <= 3) {
|
||||||
|
analogClock.setHighlight(true);
|
||||||
|
text.setForeground(Color.BLUE);
|
||||||
|
}
|
||||||
|
|
||||||
if(hourRemains <= 0 && minuteRemains <= 0) {
|
if(hourRemains <= 0 && minuteRemains <= 0) {
|
||||||
sb.append("\nCongratulation :-) It is the time to go home.");
|
sb.append("\nCongratulation :-) It is the time to go home.");
|
||||||
Toaster toasterManager = new Toaster();
|
Toaster toasterManager = new Toaster();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user