J
javaner
Gast
hallo
wir sollten das flimmern des digitalen datums und der digitalen zeit weg haben. kann uns da jemand weiter helfen?
vielen dank
--------------------------------
EDIT: Code-Tags eingefügt -AlArenal
wir sollten das flimmern des digitalen datums und der digitalen zeit weg haben. kann uns da jemand weiter helfen?
vielen dank
--------------------------------
Code:
import java.awt.*;
import java.applet.*;
import java.util.*;
public class AnalogUhr extends Applet {
public void init() {
setBackground(new Color(255,255,255));
}
Image time;
Graphics2D gtime;
Calendar date;
int x=125, y=100; // Zentrum und Radius
public void paint(Graphics g) {
// Uhr Darstellen
if (time==null) {
time=createImage(this.getSize().width, this.getSize().height);
gtime=(Graphics2D)time.getGraphics();
}
//Uhr neu zeichnen wenn sich was ändert zeit korrekt darestellen//
gtime.clearRect(0,0,this.getSize().width, this.getSize().height);
gtime.setColor(new Color(0,0,0));
gtime.drawOval(x-2,x-2,4,4);
// Striche bei 3, 6, 9 und 12 Uhr erstellen
for (int i=0;i<4;i++) {
gtime.drawLine(
x+(int)((y-7)*Math.cos(Math.toRadians(90*i))),
x+(int)((y-7)*Math.sin(Math.toRadians(90*i))),
x+(int)(y*Math.cos(Math.toRadians(90*i))),
x+(int)(y*Math.sin(Math.toRadians(90*i))));
}
// Striche bei jeder Stunde erstellen
for (int i=0;i<12;i++) {
gtime.drawLine(
x+(int)((y-5)*Math.cos(Math.toRadians(30*i))),
x+(int)((y-5)*Math.sin(Math.toRadians(30*i))),
x+(int)(y*Math.cos(Math.toRadians(30*i))),
x+(int)(y*Math.sin(Math.toRadians(30*i))));
}
//akutelle zeit implementieren//
date = new GregorianCalendar();
int hours = date.get(Calendar.HOUR_OF_DAY);
int minutes = date.get(Calendar.MINUTE);
int seconds = date.get(Calendar.SECOND);
int day = date.get(Calendar.DATE);
int month = (date.get(Calendar.MONTH))+1;
int year = date.get(Calendar.YEAR);
// Stundenzeiger
gtime.drawLine(
x,x,x+(int)(60*Math.cos(Math.toRadians(hours%12*30+minutes/2.0-90))),
x+(int)(60*Math.sin(Math.toRadians(hours%12*30+minutes/2.0-90))));
// Minutenzeiger
gtime.drawLine(
x,x,x+(int)(85*Math.cos(Math.toRadians(minutes*6-90))),
x+(int)(85*Math.sin(Math.toRadians(minutes*6-90))));
// Sekundenzeiger
gtime.setColor(new Color(170,170,170));
gtime.drawLine(
x,x,x+(int)(90*Math.cos(Math.toRadians(seconds*6-90))),
x+(int)(90*Math.sin(Math.toRadians(seconds*6-90))));
g.drawImage (time, 0, 0, this);
repaint();
//anzeige datum aktuelle uhrzeit
g.drawString(""+day+". "+month+". "+year, 65,260);
g.drawString(""+hours+". "+minutes+". "+seconds, 125,260);
}
// überschreiben / updaten//
public void update(Graphics g) {paint(g);}
}
EDIT: Code-Tags eingefügt -AlArenal