Hi,
chciałbym napisać coś na kształt proste stopera.
Nie wiem tylko jak zrobić aby na bieżąco wypisywać na label czas który upłynął.
import java.awt.BorderLayout;
import java.awt.*;
import java.awt.ActiveEvent.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.util.Date;
class Stoper_Alibe extends JFrame
{
public Stoper_Alibe()
{
setSize(150, 100);
setTitle("Stoper ffff Dżaffie");
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel1 = new JPanel();
button1 = new JButton("Start");
button2 = new JButton("Stop");
label1 = new JLabel();
panel1.add(button1);
panel1.add(button2);
add(panel1, BorderLayout.EAST);
panel2 = new JPanel();
panel2.add(label1);
add(panel2, BorderLayout.SOUTH);
button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
time_start = System.currentTimeMillis();
label1.setText("");
}
});
button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
time_stop = System.currentTimeMillis();
label1.setText("" +(( time_stop - time_start) / 1000 ));
}
});
repaint();
}
private JPanel panel1;
private JPanel panel2;
private JLabel label1;
private JButton button1;
private JButton button2;
private long time_start;
private long time_stop;
}
public class Stoper
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
( new Stoper_Alibe()).setVisible(true);
}
}
);
}
}
Proszę o pomysły.
Pozdrawiam!