package gui;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
/**
* @author marco
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Aufgabe1 extends JFrame {
private JButton _btn = null;
private JLabel _lbl = null;
private boolean _btnStopp = false;
public Aufgabe1(){
Container contentPane=getContentPane ();
contentPane.setLayout(new FlowLayout());
_btn = new JButton("stopp");
_btn.addActionListener(
new ActionListener()/*WARUM*/{
public void actionperformed(ActionEvent e);
{
if(_btnStopp){
_btnStopp=false;
_btn.setText("Stopp");
}
else{
_btnStopp=true;
_btn.setText("Weiter");
}
}
});
_lbl=new JLabel();
updateLabel (new Date());
contentPane.add(_btn);
setTitle("Uhrzeit");
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new Aufgabe1Thread().start();
}
private void updateLabel(Date date){
if(!_btnStopp)
_lbl.setText(new SimpleDateFormat("HH:mm:ss").format(date));
}
private class Aufgabe1Thread extends Thread{
public void run(){
try{
for(;;){
sleep(1000);
updateLabel(new Date());
}
}catch (InterruptedException e){}
}
}
public static void main (String [] args){
new Aufgabe1();
}
}