Jumat, 22 Mei 2015

Contoh Program GUI Jam Digital Java





Source Code:
package putra4;

import javax.swing.*;
import java.awt.event.*;
import java.util.Date;
import java.awt.*;
class JCjam extends JFrame {
    JLabel tampil_jam = new JLabel();
    public JCjam() {
        tampil_jam.setFont(new Font("JuruCoding", 1, 30));
        this.getContentPane().setLayout(new FlowLayout());
        this.getContentPane().add(tampil_jam);
        ActionListener taskPerformer = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                String jc_jam = "";
                String jc_menit = "";
                String jc_detik = "";
                Date JC = new Date();
                int nilai_jam = JC.getHours();
                int nilai_menit = JC.getMinutes();
                int nilai_detik = JC.getSeconds();
                if (nilai_jam <= 9){
                    jc_jam = "0";
                }
                if (nilai_menit <= 9) {
                    jc_menit = "0";
                }
                if (nilai_detik <= 9) {
                    jc_detik = "0";
                }
                String jam = jc_jam + Integer.toString(nilai_jam);
                String menit = jc_menit + Integer.toString(nilai_menit);
                String detik = jc_detik + Integer.toString(nilai_detik);
                tampil_jam.setText("  " + jam + " : " + menit + " : " + detik + "  ");
            }
        };
        new Timer(1000, taskPerformer).start();
    }
   }
    public class putra4 {
    public static void main(String[] JuruCoding) {
        JCjam jc = new JCjam();
        jc.setTitle("Jam Digital");
        jc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jc.setSize(200, 100);
        jc.show();
    }
 }


UML:






Tidak ada komentar:

Posting Komentar