有个applet 问题

gucl79 gucl79 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是一个文字移动的applet。
但是程序开始之后,文字会有跳跃。而且每次运行的时候跳跃的距离不一样。
程序设计上是,程序载入之后,文字移动15, 然后sleep(100)之后,然后再移动20,然后这样循环。

但实际情况是,程序一运行。第一次不是跳跃15,有可能跳了30,或者45,60之类。。就是连续跳了好几次,中间没有sleep。然后有了第一次sleep之后,后面就正常了。

源代码入下。

/*
* Created on 2006-3-12
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author Chunlei Gu
* @version 1.0, March 12,2006
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.*;
import java.applet.*;

public class SimpleJavaApplet extends Applet implements Runnable{
Thread animation;
AudioClip music;
Image background;

final static int screenWidth=400;
final static int screenHeight=400;
final static int moveDistance=15;
final static int frameDelay=1000;
private String messageParam="message_param";
private String imageParam="image_param";
private String audioParam="audio_param";

String message="";
String imageName="";
String audioName="";



int xPosition=screenWidth/2;
int yPosition=screenWidth/2;
int fontSizeCurrent=30;

boolean moveUp=true;

public void init (){

//message=this.getParameter(messageParam);
//imageName=this.getParameter(imageParam);
//audioName=this.getParameter(audioParam);

message="welcome";
imageName="image.jpg";
audioName="audio.mid";

background=getImage(getDocumentBase(),imageName);
music=getAudioClip(getDocumentBase(),audioName);
setSize(screenWidth,screenHeight);
music.loop();
}

public void paint(Graphics g){
g.drawImage(background,0,0,this);

if (moveUp){
g.setFont(new Font("Times New Roman",Font.BOLD,fontSizeCurrent));
//fontSizeCurrent+=2;
g.setColor(Color.RED);
if (yPosition>0&& yPosition<screenHeight){
yPosition-=moveDistance;
System.out.println(yPosition);
}
else if (yPosition<=0){
moveUp=false;
yPosition+=moveDistance;
System.out.println(yPosition);
}
}
else{
g.setFont(new Font("Arial",Font.ITALIC,fontSizeCurrent));
//fontSizeCurrent-=2;
g.setColor(Color.BLUE);
if (yPosition<screenHeight){
yPosition+=moveDistance;
System.out.println(yPosition);
}
else if(yPosition>=screenHeight){
moveUp=true;
yPosition-=moveDistance;
System.out.println(yPosition);
}
}

g.drawString(message,xPosition,yPosition);
System.out.println(xPosition+"---"+yPosition);
}



public void start(){
try{
if (this.animation==null){
System.out.println("animation==null");
this.animation=new Thread(this );
System.out.println("new animation ");
this.animation.start();
System.out.println(" animation start");
}
else{
this.animation.start();
System.out.println("animation!=null");
System.out.println(" animation start");
}
}catch (Exception ex){
System.out.println("error:"+ex);
}
}

public void run(){


try{
while (true){
repaint();
System.out.println("try repaint();");
//this.animation.sleep(frameDelay);
Thread.sleep(frameDelay);
System.out.println("sleep ;");
}
}catch (InterruptedException ex){
System.out.println("error"+ex);
}

}

public boolean mouseDown (Event e, int x, int y){
//if(this.animation != null&&this.animation.isAlive()){
//this.stop();
//this.animation=null;
//}
yPosition=screenHeight/2;
this.repaint();
moveUp=true;
fontSizeCurrent=30;
return true;
}


public void update(Graphics g){

paint(g);
System.out.println("update");
}

}

由于测试基本每行都加了system.out.println();

其中一次的运行结果如下:从中可以发现从200到一直减到35的时候才sleep一次。
animation==null
new animation
try repaint();
animation start
185
200---185
170
200---170
155
200---155
140
200---140
125
200---125
110
200---110
95
200---95
80
200---80
65
200---65
50
200---50
sleep ;
35
200---35
try repaint();
sleep ;
20
200---20
try repaint();
...全文

相关推荐

在eclipse中运行java applet时的一些问题

在eclipse中运行java applet时的一些问题,无法显示图片。

im110

UCF101动作识别实战:3D CNN与CNN+RNN双路线复现与调参全记录

视频理解是计算机视觉领域的重要方向,其核心任务之一是动作识别,即在连续帧中判断人体或物体的动态行为。面对视频数据额外的时间维度,深度学习模型需要同时捕捉空间纹理与时间运动,因此衍生出两种主流技术路线:基于3D CNN的时空卷积网络(如C3D),以及结合2D CNN与循环神经网络的时序建模方案(如CNN+RNN)。本文以UCF101基准数据集为实验平台,系统梳理了这两种架构从数据预处理、网络设计到训练调参的完整工程实践,并深入剖析了视频抽帧、时序采样、预训练迁移、过拟合抑制等关键环节的注意事项。无论你是刚入门

北美R哥

9、脊椎定位与识别:基于3D卷积和循环神经网络的创新方法

本文提出了一种结合3D卷积神经网络(CNN)和双向循环神经网络(RNN)的创新方法,用于实现脊椎的自动定位与识别。该方法通过深度多任务3D CNN提取局部3D上下文特征,利用全卷积网络(FCN)高效处理大尺寸CT图像,并引入双向RNN捕获脊椎间的长距离空间依赖关系,显著提升了在复杂临床场景下的定位与识别准确率。实验表明,该方法在具有挑战性的数据集上性能优于现有技术,尤其适用于存在手术植入物、病理变形和视野狭窄等情况。该技术可广泛应用于辅助诊断、手术规划及医学研究,具有重要的临床价值和发展前景。

pink

applet下载操作及权限问题

applet下载操作实例,对本地文件操作署名问题。

lijianhong520

applet z-index 问题

div弹出层为什么覆盖不了applet呢? 我在这个例子里面把例子弄上去了。 参考一下就明白了。

piedra
评论 4
收藏 已收藏
分享
返回顶部
gucl79
Java SE 62,621 成员 307,251 内容