public class myClock extends JFrame implements Runnable {
static myClock cl = new myClock();
static Thread thrd = new Thread(cl);
public static void main(String[] args) {
cl.setVisible(true);
thrd.start();
}
public void run() {
while(true) {
repaint();
try {
thrd.sleep(1000);
} catch(InterruptedException e) {
e.printStackTrace();
}
}
}
class GPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("test", 80, 40);
}
}
myClock() {
setSize(240, 70);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new GPanel(), BorderLayout.CENTER);
}
}