Sound s
public StartDi(Sound s){
this.s=s
}
public void run(){
s.ding()
}
}
public class StartDo implements Runnable{
Sound s
public StartDo(Sound s){
this.s=s
}
public void run(){
s.dong()
}
}
这两个子类的春枝芹run方法搭颤都扒毕是只执行一次而已啊。
你可以改为
public class StartDi implements Runnable{
Sound s
public StartDi(Sound s){
this.s=s
}
public void run(){
while(true){
s.ding()
}
}
}
public class StartDo implements Runnable{
Sound s
public StartDo(Sound s){
this.s=s
}
public void run(){
while(true){
s.dong()
}
}
}
//槐如或jdk 7X,eclipse 3.7X测试通过import java.awt.Graphics
import java.util.Date
import javax.swing.JFrame
public class Clock extends JFrame implements Runnable{
//窗口大小
final int WIDTH=300
final int HEIGHT=300
//用来获取当铅伍前时间
Date now
Clock(){
//装配桌面
setLocation(300,300)
setSize(WIDTH,HEIGHT)
setVisible(true)
setDefaultCloseOperation(EXIT_ON_CLOSE)
now=new Date()
}
public void paint(Graphics g){
//清屏
g.clearRect(0, 0, WIDTH, HEIGHT)
//写时间
g.drawString(now.toString(), 50, 50)
}
public void run() {
while(true){
try {
Thread.sleep(100)
} catch (InterruptedException e) {
}
now=new Date()
repaint()/橡滚/重绘
}
}
public static void main(String[] args){
(new Clock()).run()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)