Tugas Membuat Jam Digital
Digital Clock
Tugas PBO A
Kali ini saya akan membahas tentang bagaimana membuat jam digital menggunakan aplikasi BlueJ. Pertama anda tentunya harus memiliki source codenya, berikut :
1. Source Code Clock
/**
* Write a description of class Clock here.
*
* @author (Yuki Yanuar Ratna)
* @version (26-09-2018)
*/
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;
JTextField timeF;
JPanel panel;
public Clock()
{
super("Java Clock by Yuki Yanuar Ratna");
setSize(225,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(true); //for now
setLocationRelativeTo(null);
//initialize the panel
panel = new JPanel();
panel.setLayout(new FlowLayout());
timeF = new JTextField(5);
timeF.setEditable(false);
timeF.setFont(new Font("Arial",Font.PLAIN,48));
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);
int sec = rightNow.get(Calendar.SECOND);
timeF.setText(hour+":"+min+":"+sec);
}
}
}
2. Source Code Executor
/**
* Write a description of class Executor here.
*
* @author (Yuki Yanuar Ratna)
* @version (26-09-2018)
*/
public class Executor
{
public static void main (String[]args)
{
new Executor();
}
public Executor()
{
new Clock();
}
}
3. Dan berikut adalah langkah-langkah untuk mengetahui hasil akhirnya
Sekian, semoga bermanfaat
Komentar
Posting Komentar