| 发表于:2007-01-03 17:03:50 楼主 |
我在applet小程序中写了个文字的走马灯的效果,如果用了双缓冲技术(update(graphics g)的方法以后,那些文字会重叠在一起。如果不用就不会出现这个问题。但是不用双缓冲技术的话,那个显示的界面会很闪。 怎样才能解决这个问题? 或者给个例子出来 下面是程序的代码: import java.awt.*; import java.applet.*; import java.util.date; public class clock extends applet implements runnable { thread clockthread; font font; string s= "大 家 好 ! ! "; int count=0; public void init() { font = new font( "timesroman ",font.bold,48); } public void start() { if(clockthread==null) clockthread=new thread(this, "showtime "); clockthread.start(); } public void run() { //while(clockthread!=null) while(true) { repaint(); try{ clockthread.sleep(300); } catch(interruptedexception e){} } } public void paint(graphics g) { double a,b,c,d,e,f; int h,i,j,k,l,m; date now=new date(); a=now.getseconds(); b=now.getminutes(); c=now.gethours(); d=(a-15)*math.pi/180*6; e=(b-15)*math.pi/180*6; f=(c-15)*math.pi/180*6; h=(int)(math.sin(d)*65); i=(int)(math.cos(d)*65); j=(int)(math.sin(e)*54); k=(int)(math.cos(e)*54); l=(int)(math.sin(f)*44); m=(int)(math.cos(f)*44); g.translate(100,100); play(getdocumentbase(), "a.wav "); g.drawline(0,0,i,h); g.drawline(0,0,k,j); g.drawline(0,0,m,l); g.drawstring(now.gethours()+ ": "+now.getminutes()+ ": "+now.getseconds(),-10,100); char[] s1=s.tochararray(); int n1; string q=new string(); for(n1=count;n1 <s1.length;n1++){ q+=s1[n1]; } count++; g.drawstring(q,100,100); if(count==s1.length) { count=0; } g.drawstring(s,100,110); g.drawstring(s,160,120); } public void update(graphics g){//双缓冲技术 paint(g); } public void stop() { clockthread.stop(); } } 帮帮看看拉 |
|
|
|
|