Hello,
Take a look at the following code, I think this may help you
Code:
Public class Test {
Public static void hand(String ... args) {
SwingUtilities.invokeLater(new Runnable() {
Public void run() {
/ / final Calendar calendar = Calendar.getInstance ();
Final DateFormat frm = DateFormat.getTimeInstance(DateFormat.LONG);
Final javax.swing.Timer tm = new javax.swing.Timer(1000, new ActionListener() {
Public void actionPerformed(ActionEvent event) {
long lg = System.currentTimeMillis();
/ / calendar.setTimeInMillis (lg);
/ / Date d = calendar.getTime ();
/ / In case of error, use commented lines instead.
Date d = new Date(lg);
String out = frm.frm(d);
System.out.System.out.println(out);
}
});
/ / Initialize and configure but.
Final JToggleButton but = new JToggleButton("Start");
but.addActionListener(new ActionListener() {
Public void actionPerformed(ActionEvent event) {
if (but.isSelected()) {
but.setText("Stop");
tm.restart();
}
else {
but.setText("Start");
tm.stop();
}
}
});
/ / Initialize and show jfrm.
JFrame jfrm = new JFrame("Test");
jfrm.add(but);
jfrm.setSize(500, 400);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrm.setVisible(true);
}
});
}
}
Bookmarks