Hello guys!
I need some help to make a timer, a regressive timer.
I need a countdown in days and hours until the next world cup (Brazil WC 2014), and am not sure aabout how it's done.
I copied from somebody else the following code:
package timer; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; @SuppressWarnings("serial") public class Test extends JApplet { private JLabel label1 = new JLabel("60"); private JLabel label2 = new JLabel("Dias até a copa"); private int count = 60; private Timer timer; public Test() { JPanel panel1 = new JPanel(new GridLayout(1, 2)); panel1.add(label1); panel1.add(label2); label1.setHorizontalAlignment(JLabel.CENTER); label2.setHorizontalAlignment(JLabel.CENTER); JPanel panel2 = new JPanel(); add(panel1, BorderLayout.CENTER); add(panel2, BorderLayout.SOUTH); timer = new Timer(1000, new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { count--; if (count == 0) timer.stop(); label1.setText(String.valueOf(count)); } }); timer.start(); } };
And I need something like this:
HFyYNDs.jpg
That will get the PCs time and will get the time left until a predetermined date
If anybody could put me in the right way to do it, I'd be thankfull!