Horloge analogique
Fermé
ccjb5532
Messages postés
35
Date d'inscription
vendredi 27 octobre 2017
Statut
Membre
Dernière intervention
7 janvier 2019
-
Modifié le 30 nov. 2017 à 13:19
ccjb5532 Messages postés 35 Date d'inscription vendredi 27 octobre 2017 Statut Membre Dernière intervention 7 janvier 2019 - 3 déc. 2017 à 21:21
ccjb5532 Messages postés 35 Date d'inscription vendredi 27 octobre 2017 Statut Membre Dernière intervention 7 janvier 2019 - 3 déc. 2017 à 21:21
A voir également:
- Horloge analogique
- Horloge mondiale gratuite - Télécharger - Divers Utilitaires
- Votre horloge est en avance - Forum Windows Vista
- Analogique gestion alim - Forum Vidéo/TV
- Logiciel acquisition vidéo analogique gratuit windows 10 - Télécharger - Montage & Édition
- Problème horloge pc windows 7 - Forum Windows
1 réponse
titoineis14270
Messages postés
14
Date d'inscription
samedi 2 décembre 2017
Statut
Membre
Dernière intervention
3 décembre 2017
2
3 déc. 2017 à 20:17
3 déc. 2017 à 20:17
Cela fonctionne pour moi mais utilise des outils tels que les Thread.
public class AnalogTimer extends JFrame {
public int hour;
public int min;
public int sec;
ClockDial cd;
public AnalogTimer() {
setSize(510, 530);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
cd = new ClockDial(this);
getContentPane().add(cd);
Date curr = new Date();
String time = curr.toString();
hour = Integer.parseInt(time.substring(11, 13));
min = Integer.parseInt(time.substring(14, 16));
sec = Integer.parseInt(time.substring(17, 19));
ClockEngine.setPriority(ClockEngine.getPriority() + 3);
ClockEngine.start();
}
public static void main(String args[]) {
new AnalogTimer().setVisible(true);
}
Thread ClockEngine = new Thread() {
int newsec, newmin;
public void run() {
while (true) {
newsec = (sec + 1) % 60;
newmin = (min + (sec + 1) / 60) % 60;
hour = (hour + (min + (sec + 1) / 60) / 60) % 12;
sec = newsec;
min = newmin;
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
cd.repaint();
}
}
};
}
class ClockDial extends JPanel {
AnalogTimer parent;
public ClockDial(AnalogTimer pt) {
setSize(520, 530);
parent = pt;
}
@Override
public void paintComponent(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.WHITE);
g.fillOval(5, 5, 480, 480);
g.setColor(Color.BLACK);
g.fillOval(10, 10, 470, 470);
g.setColor(Color.WHITE);
g.fillOval(237, 237, 15, 15);
g.setFont(g.getFont().deriveFont(Font.BOLD, 32));
for (int i = 1; i <= 12; i++)
g.drawString(Integer.toString(i), 240 - (i / 12) * 11 + (int) (210 * Math.sin(i * Math.PI / 6)), 253 - (int) (210 * Math.cos(i * Math.PI / 6)));
double minsecdeg = (double) Math.PI / 30;
double hrdeg = (double) Math.PI / 6;
int tx, ty;
int xpoints[] = new int[3];
int ypoints[] = new int[3];
//secondes
tx = 245 + (int) (210 * Math.sin(parent.sec * minsecdeg));
ty = 245 - (int) (210 * Math.cos(parent.sec * minsecdeg));
g.drawLine(245, 245, tx, ty);
//minutes
tx = 245 + (int) (190 * Math.sin(parent.min * minsecdeg));
ty = 245 - (int) (190 * Math.cos(parent.min * minsecdeg));
xpoints[0] = 245;
xpoints[1] = tx + 2;
xpoints[2] = tx - 2;
ypoints[0] = 245;
ypoints[1] = ty + 2;
ypoints[2] = ty - 2;
g.fillPolygon(xpoints, ypoints, 3);
//heures
tx = 245 + (int) (160 * Math.sin(parent.hour * hrdeg + parent.min * Math.PI / 360));
ty = 245 - (int) (160 * Math.cos(parent.hour * hrdeg + parent.min * Math.PI / 360));
xpoints[1] = tx + 4;
xpoints[2] = tx - 4;
ypoints[1] = ty - 4;
ypoints[2] = ty + 4;
g.fillPolygon(xpoints, ypoints, 3);
}
}

3 déc. 2017 à 20:39
il est possible que la question soit un exercice, il y a une politique à respecter concernant les devoirs:
https://www.commentcamarche.net/infos/25899-demander-de-l-aide-pour-vos-exercices-sur-ccm/
et
http://codes-sources.commentcamarche.net/forum/affich-1557761-bar-sujet-de-pfe-tp-et-autres-devoirs-scolaires#top
Là tu lui jettes en pâture un code avec des Thread, alors qu'il a bien précisé être vraiment débutant. S'il s'agit bien d'un devoir, son prof saura tout de suite que ça n'est pas de lui.
Et s'il ne s'agit pas d'un exercice, un tel code sans contexte ni commentaires sera difficilement compréhensible.
Je ne cherche pas à te démotiver à aider, mais à t'aider à mieux aider
3 déc. 2017 à 21:21