JAM
29 September 2018
Nama : Sherly Rosa Anggraeni
NRP : 05111740000018
Kelas : PBO-A
Source Code
1. Main Program
/**
* Test Jam
*
* Sherly Rosa Anggraeni
* 05111740000018
* PBO-A
*/
public class main
{
private int limit;
private int value;
public main(int overlimit){
limit=overlimit;
value=0;
}
public int getvalue(){
return value;
}
public String getdisplayvalue()
{
if(value<10)
{
return "0" + value;
}
else{
return "" + value;
}
}
public void setvalue(int replacevalue){
if((replacevalue>=0)&&(replacevalue<limit))
{
value=replacevalue;
}}
public void increment(){
value=(value+1)%limit;}
}
2. Display
/**
* Test Jam
*
* Sherly Rosa Anggraeni
* 05111740000018
* PBO-A
*/
public class display
{
private main jam;
private main menit;
private String displays;
public display(){
jam = new main(24);
menit = new main(60);
updatedisplay();
}
public display(int hour, int minute){
jam = new main(24);
menit = new main(60);
aturwaktu(hour,minute);
}
public void timeTick(){
menit.increment();
if(menit.getvalue()==0){
jam.increment();
}
updatedisplay();
}
public void aturwaktu(int hour, int minute){
jam.setvalue(hour);
menit.setvalue(minute);
updatedisplay();
}
public String gettime()
{
return displays;
}
private void updatedisplay()
{
displays=jam.getdisplayvalue()+"."+menit.getdisplayvalue();}
}
3. Test Jam
/**
* Test Jam
*
* Sherly Rosa Anggraeni
* 05111740000018
* PBO-A
*/
public class test
{
public test(){
}
public void tes(){
display clock = new display();
clock.aturwaktu(9,06);
System.out.println(clock.gettime());
clock.aturwaktu(22,35);
System.out.println(clock.gettime());
clock.aturwaktu(15,12);
System.out.println(clock.gettime());
clock.aturwaktu(12,55);
System.out.println(clock.gettime());
clock.aturwaktu(23,59);
System.out.println(clock.gettime());
}
}
4. Executor
public class Ex{
public static void main(String[]args) {
new Ex();
}
public Ex() {
new clock();
}
}
5. Clock
// by ilikechess1
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
public class clock extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
// components
JTextField timeF;
JPanel panel;
public clock() {
// housekeeping
super("Java Clock by [insert your name here]");
setSize(225,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(true);// for now
setLocationRelativeTo(null);
panel = new JPanel();
panel.setLayout(new FlowLayout());
timeF = new JTextField(10);
timeF.setEditable(false);
timeF.setFont(new Font("Times New Roman", Font.PLAIN, 100));
panel.add(timeF);
add(panel);
Timer t = new Timer(1000, new Listener());
t.start();
}
class Listener implements ActionListener{
public void actionPerformed(ActionEvent e){
Calendar rightNow = Calendar.getInstance();
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
int min = rightNow.get(Calendar.MINUTE);
timeF.setText(hour+":"+min);
}
}
}
Tidak ada komentar:
Posting Komentar