Analoge Uhr in GUI | gebe 73e*g

10/27/2015 20:26 _ᴋush##1
Hey Leute!

Ich hab im Internet gesucht und gesucht.. aber ich finde es einfach nicht.

brauche einfach eine große analoge Uhr mit Sekundenanzeige.

Natürlich in einer GUI als .class Datei.

Würde 73e*g bieten!

Wär super, wenn ihr mir sowas programmieren könntet :)
(dauert ja nicht lange oder?)

Gruß,
kush
10/27/2015 21:44 Belur#2
Also wenn ich nach "java analog clock" google, gibts da mehrere fertige Lösungen.

Hier mal eine: [Only registered and activated users can see links. Click Here To Register...]
10/28/2015 07:59 _ᴋush##3
Sorry, hab mich vertan ich meine eine digitale Uhr und da finde ich nur .java files..
10/28/2015 09:25 Mysthik#4
Soll die eine einfache Anzeige haben oder eine siebensegment Anzeige?
JavaFX oder Swing?
10/28/2015 11:25 _ᴋush##5
JavaFX und eine einfache Anzeige

Edit: Hat sich erledigt. Habe einen Code gefunden, war zu blöd zu suchen :D

Code:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.WindowConstants;

public class SimpleDigitalClock {

    public static void main(String[] args) {

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        DigitalClock myClock = new DigitalClock();
        f.add(myClock);
        f.pack();
        f.setVisible(true);
    }

    static class DigitalClock extends JPanel {

        String stringTime;
        int hour, minute, second;

        String correctionHour = "";
        String correctionMinute = "";
        String correctionSecond = "";

        public void setStringTime(String xyz) {
            this.stringTime = xyz;
        }

        public int findMinimumBetweenTwoNumbers(int a, int b) {
            return (a <= b) ? a : b;
        }

        DigitalClock() {

            Timer t1 = new Timer(1000, new ActionListener() {
                public void actionPerformed(ActionEvent e) {

                    repaint();
                }
            });
            t1.start();
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Calendar now = Calendar.getInstance();
            hour = now.get(Calendar.HOUR_OF_DAY);
            minute = now.get(Calendar.MINUTE);
            second = now.get(Calendar.SECOND);

            if (hour < 10) {
                this.correctionHour = "0";
            }
            if (hour >= 10) {
                this.correctionHour = "";
            }

            if (minute < 10) {
                this.correctionMinute = "0";
            }
            if (minute >= 10) {
                this.correctionMinute = "";
            }

            if (second < 10) {
                this.correctionSecond = "0";
            }
            if (second >= 10) {
                this.correctionSecond = "";
            }
            setStringTime(correctionHour + hour + ":" + correctionMinute+ minute + ":" + correctionSecond + second);
            g.setColor(Color.BLACK);
            int length = findMinimumBetweenTwoNumbers(this.getWidth(),this.getHeight());
            Font myFont = new Font("SansSerif", Font.PLAIN, length / 5);
            g.setFont(myFont);
            g.drawString(stringTime, (int) length/6, length/2);

        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }

    }

}
Der Code btw.