谁帮我看看为什么我想显示的时间标签在applet中没有反应??效果应该是从右到左循环移动的,但是我的却没反应??请高手赐教,回答正确40分全给了。import java.awt.*;
import java.applet.Applet;
import java.util.Calendar;
import java.util.GregorianCalendar;
class Clock8 extends Label implements Runnable{
Thread thread;
public Clock8(){
if(thread==null){
thread=new Thread(this);
thread.start();
}
}
@Override
public void run() {
String s = "";
while (true) {
Calendar c = new GregorianCalendar();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
String ss = "";
String mm = "";
String hh = "";
ss = second < 10 ? "0" + String.valueOf(second) : String.valueOf(second);
mm = minute < 10 ? "0" + String.valueOf(minute) : String.valueOf(minute);
hh = hour < 10 ? "0" + String.valueOf(hour) : String.valueOf(hour);
s = hh + ":" + mm + ":" + ss;
this.setText(s);
this.setFont(new Font("",Font.BOLD,60));
this.setForeground(Color.YELLOW);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
}
}
}
public class RollWords extends Applet implements Runnable {
Clock8 c1=new Clock8();
private String rollWords;
private int size;
private int color;
int x, y;
Thread rollThread = null;
public void init() {
rollWords= c1.getText();
// rollWords =cl.getText() ;
// size = Integer.parseInt(getParameter("size"));
// color = Integer.parseInt(getParameter("color"));
size = 18;
color = 1800;
x = 390;
y = 40;
}
@Override
public void paint(Graphics g) {
Color c = new Color(color);
g.setColor(c);
Font f = new Font("", 1, size);
g.setFont(f);
g.drawString(rollWords, 300 - x, y);
}
@Override
public void start(){
if(null == rollThread){
rollThread = new Thread(this);
rollThread.start();
}
}
public void run() {
while (true) {
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
x = (x+5)%400;
}
}
}
------解决方案--------------------