自己随便搞了个程序为什么它这么闪 ?有解决办法没??

rongyunsheng 2008-06-02 10:42:05
跟repaint()有关???还是我颜色搞的太多??不明白 请解释下…………

import java.awt.*;
import javax.swing.*;
public class TestThread2 extends JApplet implements Runnable{
private Image ImageMaker;
private Graphics ImageGraphics;
Thread Threadme=null;
private int x=0;
private final static int y=225;
private final static int x1=450;
private int y1=225;
private int move1=10;
private int move2=5;


public void init(){
ImageMaker=this.createImage(600,600);
ImageGraphics=ImageMaker.getGraphics();
}
public void start(){
if(Threadme==null){
Threadme=new Thread(this);
Threadme.start();
}
}
public void run(){
Thread myThread=Thread.currentThread();
while(Threadme==myThread){
x+=move1;
y1+=move2;
if(x>=450||x<=0){move1*=-1;}
if(y1>=450||y1<=0){move2*=-1;}
repaint();
}

}

public void drawOval(Graphics g){
Graphics2D g1=(Graphics2D)g;
g1.setColor(Color.magenta);
g1.fillRect(0,0,300,300);
g1.setColor(Color.green);
g1.fillRect(300,0,300,300);
g1.setColor(Color.black);
g1.fillRect(0,300,300,300);
g1.setColor(Color.BLUE);
g1.fillRect(300,300,300,300);
g1.setColor(Color.YELLOW);
g1.fillOval(x,y,150,150);
g1.setColor(Color.orange);
g1.fillOval(x1,y1,150,150);
}

public void paint(Graphics ImageGraphics){
ImageGraphics.setColor(Color.white);
ImageGraphics.fillRect(0,0,getSize().width,getSize().height);
drawOval(ImageGraphics);
ImageGraphics.drawImage(ImageMaker,600,600,Color.gray,this);
}

}
...全文
72 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
rongyunsheng 2008-06-03
  • 打赏
  • 举报
回复
按时
rongyunsheng 2008-06-02
  • 打赏
  • 举报
回复
如果我想这两个圆以圆的轨迹运动 那样怎么样实现啊 求助???
chenhongxin 2008-06-02
  • 打赏
  • 举报
回复
有意思,你让他闪的呗...
rongyunsheng 2008-06-02
  • 打赏
  • 举报
回复
不应该发这个帖子的 显我得好蠢


import java.awt.*;
import javax.swing.*;
public class TestThread2 extends JApplet implements Runnable{
private Image ImageMaker=null;
private Graphics ImageGraphics=null;
Thread Threadme=null;
private int x=0;
private final static int y=225;
private final static int x1=450;
private int y1=225;
private int move1=1;
private int move2=1;


public void init(){
ImageMaker=this.createImage(600,600);
ImageGraphics=ImageMaker.getGraphics();
}
public void start(){
if(Threadme==null){
Threadme=new Thread(this);
Threadme.start();
}
}
public void run(){
Thread myThread=Thread.currentThread();
while(Threadme==myThread){
x+=move1;
y1+=move2;
if(x>=450||x<=0){move1*=-1;}
if(y1>=450||y1<=0){move2*=-1;}
repaint();
}

}

public void drawOval(Graphics g){
Graphics2D g1=(Graphics2D)g;
g1.setColor(Color.magenta);
g1.fillRect(0,0,300,300);
g1.setColor(Color.green);
g1.fillRect(300,0,300,300);
g1.setColor(Color.black);
g1.fillRect(0,300,300,300);
g1.setColor(Color.BLUE);
g1.fillRect(300,300,300,300);
g1.setColor(Color.YELLOW);
g1.fillOval(x,y,150,150);
g1.setColor(Color.orange);
g1.fillOval(x1,y1,150,150);
}

public void paint(Graphics ImageGraphics){
//ImageGraphics.setColor(Color.white);
//ImageGraphics.fillRect(0,0,0,0);
drawOval(ImageGraphics);
ImageGraphics.drawImage(ImageMaker,600,600,this);
}

}

interpb 2008-06-02
  • 打赏
  • 举报
回复
你希望是怎么显示

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧