Java Reference
In-Depth Information
5.
private
int time;
6.
private
TimerPanel timerPane;
7.
8.
public
TimerThread(TimerPanel tp) {
9.
time = 0;
10.
timerPane = tp;
11.
}
12.
13.
public void
run(){
14.
while
(
true
){
15.
try
{
16.
Thread.sleep(500L);
17.
time += 500;
18.
System.out.println("Running "+time);
timerPane.setTime(time);
19.
}
20.
catch
(InterruptedException ex) {
21.
}
22.
}
23.
}
24.
}
25.
File:
its/Applet/TimerPanel.java
1.
package
its.Applet;
2.
3.
import
javax.swing.JPanel;
4.
import
java.awt.Color;
5.
import
java.awt.Graphics;
6.
7.
public class
TimerPanel
extends
JPanel {
8.
9.
private int
time;
10.
11.
public
TimerPanel() {
12.
this
.setBackground(Color.yellow);
13.
time = 0;
}
14.
15.
16.
public void
paintComponent(Graphics g){
super
.paintComponent(g);
17.
g.drawString(Integer.toString(time), 50,50);
18.
}
19.
20.
21.
Search WWH ::
Custom Search