berikut saya lampirkan pula source codenya:
1. clock
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 Shawn Timothy Mulya Putra");
setSize(225,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(true);
setLocationRelativeTo(null);
panel = new JPanel ();
panel.setLayout(new FlowLayout());
timeF = new JTextField(10);
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. excecutor
public class Executor {
public static void main(String[]args) {
new Executor();
}
public Executor() {
new clock();
}
}
Tidak ada komentar:
Posting Komentar