Here is the UI class I have built to house my clock:
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
class DigiClock extends JFrame
{
//Clock//
Timer t;
//Buttons//
JButton startBtn = new JButton("Start");
JButton stopBtn = new JButton("Stop");
JButton pauseBtn = new JButton("Pause");
JButton resumeBtn = new JButton("Resume");
//Labels//
JLabel clockFace = new JLabel();
//Docks//
JPanel buttonDock = new JPanel();
//Handlers//
ButtonHandler bHandler = new ButtonHandler();
DigiClock()
{
setupGUI();
}
private void setupGUI()
{
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(BorderLayout.CENTER, clockFace);
c.add(BorderLayout.SOUTH, buttonDock);
buttonDock.setLayout(new GridLayout(1,4));
buttonDock.add(startBtn);
startBtn.addActionListener(bHandler);
buttonDock.add(stopBtn);
buttonDock.add(pauseBtn);
buttonDock.add(resumeBtn);
setTitle("DigiClock v0.1");
setSize(350,100);
setVisible(true);
}
public class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("Start"))
{
t.run();
}
}
}
}
And here is my timer, barely modified from the timer I created some weeks ago in another task. This task requires I take this timer and thread it.
public class Timer
{
int interval;
Client client;
Timer(Client client, int interval)
{
this.client = client;
this.interval = interval;
}
public void run()
{
while(true)
{
for(int i=0; i<interval; i++);
client.timerFired();
}
}
}
public class Client
{
Client()
{
Timer t = new Timer(this, 100000000);
}
public void timerFired()
{
System.out.println("Timer method fired.");
}
}
There is also a Main.java file that runs a main method that creates one instance of DigiClock and one instance of Client.
Thank you in advance for any help.

New Topic/Question
Reply




MultiQuote





|