Skip to main content

Clock

Pembuatan Clock menggunakan BlueJ

Class yang digunakan sebagai berikut :

  1. Main Clock : digunakan sebagai penghubung antara NumberDisplay dan ClockMechanics
  2. NumberDisplay : digunakan sebagai format output number pada jam
  3. ClockMechanics : digunakan sebagai pengatur mekanisme jam
Main Clock Source Code

import java.util.concurrent.TimeUnit;
/**
 * MainClock class as connector NumberDisplay and ClockMechanics class
 *
 * @author Satria Ade Veda Karuniawan
 * @version Version 1.0
 */
public class MainClock
{
    NumberDisplay numberobj = new NumberDisplay();
    ClockMechanics clockobj = new ClockMechanics();
    int Marker = 0;
    private String[] time_now = {"","","","","","",""};
    private String[] converter = new String[7];
    public MainClock()
    {
        while(true)
        {
                Reset();
                clockobj.UpdateTime();
                SetTime();
                Print();
             

        }

    }
 
    public void Reset()
    {
        for(int a = 0; a < 7; a++)
        {
            time_now[a] = "";
        }
    }
 
    public void Print()
    {
        for(int a = 0; a < 7; a++)
        {
            if(time_now[a]!=null)
            {
                System.out.println(time_now[a]);
            }
        }
     
        System.out.println("                                                          " + (clockobj.GetMonth()+1) + "/" + clockobj.GetDay() + "/" + clockobj.GetYear());
    }
 
    public void ConvertNumber(int x)
    {
        converter = numberobj.ChooseNumber(x);
        Marker++;
        for(int a = 0; a < 7; a++)
        {
            if((a == 2 || a == 4) && (Marker == 2 || Marker == 4))
            {
                time_now[a] += converter[a] + "█";
       
            }
            else
            {
                time_now[a] += converter[a] + "░";
            }
        }
    }
 
    public void SetTime()
    {
        int seconddigit1 = clockobj.GetSecond()%10;
        int seconddigit2 = (clockobj.GetSecond()/10)%10;
        int minutedigit1 = clockobj.GetMinute()%10;
        int minutedigit2 = (clockobj.GetMinute()/10)%10;
        int hourdigit1 = clockobj.GetHour()%10;
        int hourdigit2 = (clockobj.GetHour()/10)%10;
     
        ConvertNumber(hourdigit2);
        ConvertNumber(hourdigit1);
        ConvertNumber(minutedigit2);
        ConvertNumber(minutedigit1);
        ConvertNumber(seconddigit2);
        ConvertNumber(seconddigit1);
        Marker = 0;
    }
}


Number Display Source Code


/**
 * NumberDisplay as a formatting output class
 *
 * @author Satria Ade Veda Karuniawan
 * @version Version 1.0
 */
public class NumberDisplay
{
    //Pallet ░▒▓█■▄▀
 
    public String[] ChooseNumber(int Number)
    {
        String[] SevenSegment = new String[7];
        switch(Number)
        {
            case 0:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░██░░░██░";
            SevenSegment[4] = "░██░░░██░";
            SevenSegment[5] = "░██░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 1:
            SevenSegment[0] = "░░░░░░██░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░░░░░░██░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░░░░░░██░";
            break;
         
            case 2:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░██░░░░░░";
            SevenSegment[5] = "░██░░░░░░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 3:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 4:
            SevenSegment[0] = "░██░░░██░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░░░░░░██░";
            break;
         
            case 5:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░░░░";
            SevenSegment[2] = "░██░░░░░░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 6:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░░░░";
            SevenSegment[2] = "░██░░░░░░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░██░░░██░";
            SevenSegment[5] = "░██░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 7:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░░░░░░██░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░░░░░░██░";
            break;
         
            case 8:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░██░░░██░";
            SevenSegment[5] = "░██░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 9:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░███████░";
        }
     
        return SevenSegment;
    }
}


Clock Mechanics Source Code

import java.util.*;
/**
 * ClockMechanics as clock algorithm class
 *
 * @author Satria Ade Veda Karuniawan
 * @version Version 1.0
 */
public class ClockMechanics
{
    GregorianCalendar date = new GregorianCalendar();
    private int day, month, year;
    private int second, minute, hour;
 
    public ClockMechanics()
    {
        second = date.get(Calendar.SECOND);
        minute = date.get(Calendar.MINUTE);
        hour = date.get(Calendar.HOUR);

        day = date.get(Calendar.DAY_OF_MONTH);
        month = date.get(Calendar.MONTH);
        year = date.get(Calendar.YEAR);
    }
 
    public void UpdateTime()
    {
     
     
        second++;
        if(second == 60)
        {
            second = 0;
            minute++;
        }
     
        if(minute == 60)
        {
            minute = 0;
            hour++;
        }
     
        if(hour == 12)
        {
            hour = 0;
        }
        try
            {
                Thread.sleep(1000);
            } catch(InterruptedException e)
            {
             
            }
     
        System.out.print('\u000C');
    }
 
 
    public int GetSecond()
    {
        return second;
    }
 
    public int GetMinute()
    {
        return minute;
    }
 
    public int GetHour()
    {
        return hour;
    }
 
    public int GetDay()
    {
        return day;
    }
 
    public int GetMonth()
    {
        return month;
    }
 
    public int GetYear()
    {
        return year;
    }
}

Workspace



Untuk keluar dari program setelah dijalankan

  1. Membuka tab View pada window BlueJ
  2. Pilih show Debugger (dapat melalui shortcut CTRL + D)
  3. Pilih Threads main
  4. Tekan tombol Terminate
Tampilan saat program dijalankan (Membuat object MainClock)


Comments

Popular posts from this blog

Technical Support AI

Technical Support - Artificial Intelligence (*From now on, I'll try my best to explain about all of my Project using English) For this project, I made 3 classes to control the Bot Mechanism (Referencing to Objects-First-with-Java-A-Practical-Introduction-Using-BlueJ-David-J-Barnes pages 155) : InputReader Class (Used for detect or to take any user input) SupportSystem Class (As a main function connecting the user input and database) Responder Class (Handling AI-Output and Its role as 'mini' database) Current Version : 1.2 In the future, I'm expecting to have a bigger Responder's Database and would be separated from the Class itself, so it will be easier to make some modification inside the AI's Database and easier to manage. And then i'll try to improve the UX Design inside, so that the user can have a feeling about how 'Human' this AI. InputReader Class In this class, pretty much the same as how the name of the class is writt...

Image Viewer GUI 4.0 (Final Exam Project)

Rancangan Interface (Workspace) Project lanjutan dari Image Viewer GUI 3.0 dengan implementasi menggunakan BlueJ, hal yang telah selesai diimplementasikan adalah : Frame Panel Button Label dll Dengan daftar class utama sebagai berikut : ImageViewer : merupakan class utama yang berfungsi untuk menampilkan dan menginisialisasi GUI (main class) OFImage : merupakan class yang mendefinisikan objek dari gambar ImagePanel : merupakan class yang salah satunya bertindak sebagai canvas gambar (berbeda dengan ImageViewer, ImagePanel hanya mengatur bagian panel foto saja) ImageFileManager : merupakan class yang bertindak sebagai file handler Dengan daftar inherited class ( Filter ) sebagai berikut : DarkerFilter : class Filter yang berfungsi untuk menggelapkan foto LighterFilter : class Filter yang berfungsi untuk menerangkan foto ThresholdFilter : class Filter yang berfungsi untuk merubah warna foto menjadi 3 tingkatan warna dari grayscale InvertFilter : class Fil...