郁闷!!怎样实现applet中字幕滚动效果?搞了几天都没搞出来 g.drawString(msg,50,30);这里坐标是固定的,能滚动么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 既然是通过绘图(paint)绘文字,而且要滚动,所以,g.drawString是,把坐标变化啊!比如g.drawString(msg,x,30);然后,在某地方改动x,然后通知repaint()重绘. import java.awt.*;import java.applet.*;public class applet1 extends Applet implements Runnable{ Thread t; String msg="welcome to java!"; int state=70; boolean stopflag; public void init(){ setBackground(Color.cyan); setForeground(Color.yellow); } public void start(){ t=new Thread(this); stopflag=false; t.start(); } public void run() { while(true){ state = state -1; if (state< -69) state=70; repaint(); try{ Thread.sleep(300); }catch(InterruptedException e){} } } public void stop(){ stopflag=true; t=null; } public void paint(Graphics g) { for(int i=0; i<=msg.length(); i++) g.drawString(msg.charAt(i),state+i,50) //state+i 依次绘出单个字符 //行固定不变 } 由于我在网吧上网没有调试环境 所以这个程序我并没有测试 其中可能存在一起错误,不过基本是这个思路 我会继续关注 有不清楚的给我回复 import java.awt.*;import java.applet.*;public class applet1 extends Applet implements Runnable{ Thread t; String msg="welcome to java!"; int state=70; boolean stopflag; public void init(){ setBackground(Color.cyan); setForeground(Color.yellow); } public void start(){ t=new Thread(this); stopflag=false; t.start(); } public void run() { while(true){ state = state -1; if (state< -69) state=70; repaint(); try{ Thread.sleep(300); }catch(InterruptedException e){} } } public void stop(){ stopflag=true; t=null; } public void paint(Graphics g) { for(int i=0; i<=msg.length(); i++) g.drawString(msg.charAt(i),state+i,50) //state+i 依次绘出单个字符 //行固定不变 } 由于我在网吧上网没有调试环境 所以这个程序我并没有测试 其中可能存在一起错误,不过基本是这个思路 我会继续关注 有不清楚的给我回复 unsupportedclassvertion 做项目 SWT 怎么做出右下脚慢慢升出shell的效果??就象QQ系统消息那样... 请教各位,关于接收到的UDP数据包的字节序问题 一个格式化字符串的问题 Java可以实现C++默认参数的功能吗? 在eclipse中使用tomcat插件的问题,欢迎讨论。 求Optimizeit 5 的注册机 初学者问题 studentmanage类 National Language character set是什么?有什么用? String不是引用型嗎
import java.applet.*;public class applet1 extends Applet implements Runnable{
Thread t;
String msg="welcome to java!";
int state=70;
boolean stopflag; public void init(){
setBackground(Color.cyan);
setForeground(Color.yellow);
} public void start(){
t=new Thread(this);
stopflag=false;
t.start();
} public void run()
{
while(true){
state = state -1;
if (state< -69)
state=70;
repaint();
try{
Thread.sleep(300);
}catch(InterruptedException e){}
}
} public void stop(){
stopflag=true;
t=null;
} public void paint(Graphics g)
{
for(int i=0; i<=msg.length(); i++)
g.drawString(msg.charAt(i),state+i,50) //state+i 依次绘出单个字符
//行固定不变
}
由于我在网吧上网没有调试环境 所以这个程序我并没有测试 其中可能存在一起错误,不过基本是这个思路 我会继续关注 有不清楚的给我回复
import java.applet.*;public class applet1 extends Applet implements Runnable{
Thread t;
String msg="welcome to java!";
int state=70;
boolean stopflag; public void init(){
setBackground(Color.cyan);
setForeground(Color.yellow);
} public void start(){
t=new Thread(this);
stopflag=false;
t.start();
} public void run()
{
while(true){
state = state -1;
if (state< -69)
state=70;
repaint();
try{
Thread.sleep(300);
}catch(InterruptedException e){}
}
} public void stop(){
stopflag=true;
t=null;
} public void paint(Graphics g)
{
for(int i=0; i<=msg.length(); i++)
g.drawString(msg.charAt(i),state+i,50) //state+i 依次绘出单个字符
//行固定不变
}
由于我在网吧上网没有调试环境 所以这个程序我并没有测试 其中可能存在一起错误,不过基本是这个思路 我会继续关注 有不清楚的给我回复