Pembuatan Clock menggunakan BlueJ
Class yang digunakan sebagai berikut :
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
Workspace
Untuk keluar dari program setelah dijalankan
Class yang digunakan sebagai berikut :
- Main Clock : digunakan sebagai penghubung antara NumberDisplay dan ClockMechanics
- NumberDisplay : digunakan sebagai format output number pada jam
- 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;
}
}
/**
* 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;
}
}
/**
* 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
- Membuka tab View pada window BlueJ
- Pilih show Debugger (dapat melalui shortcut CTRL + D)
- Pilih Threads main
- Tekan tombol Terminate
Tampilan saat program dijalankan (Membuat object MainClock)
Comments
Post a Comment