import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.Timer;public class ShowTime extends JFrame{ private JTextField time; public ShowTime(){ time = new JTextField(20); this.add(time); this.setSize(200,150); this.setLocation(100,100); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void refreshTime(){ Date date = new Date(); time.setText(date.toString()); }
public static void main(String args[]){ final ShowTime showTime = new ShowTime(); showTime.setVisible(true);
Timer t = new Timer(1000,new ActionListener(){ public void actionPerformed(ActionEvent e){ showTime.refreshTime(); } });
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;public class ShowTime extends JFrame{
private JTextField time;
public ShowTime(){
time = new JTextField(20);
this.add(time);
this.setSize(200,150);
this.setLocation(100,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void refreshTime(){
Date date = new Date();
time.setText(date.toString());
}
public static void main(String args[]){
final ShowTime showTime = new ShowTime();
showTime.setVisible(true);
Timer t = new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e){
showTime.refreshTime();
}
});
t.start();
}
}