import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class TimerDisplay extends JLabel implements ActionListener
{
GridLayout grid = new GridLayout (3, 3);
int count = 14;
int counter = 0;
JButton Click = new JButton ("Click Me!");
JLabel Score = new JLabel (" Score: ");
JPanel p = new JPanel ();
public TimerDisplay ()
{
super ("Remaining Time: 15 secs", JLabel.CENTER);
p.setLayout (grid);
p.add (Click);
Click.addActionListener (this);
p.add (Score);
Timer t = new Timer (1000, this);
t.start ();
this.add (p);
p.setVisible (true);
Click.setVisible(true);
Score.setVisible(true);
}
public void actionPerformed (ActionEvent ae)
{
this.setText ("Remaining Time: " + count-- + " secs");
if (ae.getSource () == Click)
{
counter += 1;
}
if (count == -1)
{
count = 0;
remove (Click);
}
Score.setText (" Score: " + counter);
}
public static void main (String arg[])
{
JFrame f = new JFrame ();
f.setSize (500, 500);
f.addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
}
);
TimerDisplay c = new TimerDisplay ();
f.getContentPane ()
.setLayout (new BorderLayout ());
f.getContentPane ()
.add (c, BorderLayout.CENTER);
f.show ();
}
}