| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 482 人关注过本帖
标题:我怎么取消不了闪烁
只看楼主 加入收藏
ck550114195
Rank: 1
来 自:河北邯郸
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-4-19
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
我怎么取消不了闪烁
test.zip (1.3 KB)

取消产闪烁时。。别的也给改变了。。
搜索更多相关主题的帖子: 闪烁 
2010-05-09 11:31
dadongzicool
Rank: 6Rank: 6
等 级:贵宾
威 望:11
帖 子:209
专家分:474
注 册:2009-3-20
收藏
得分:20 
重写一下update

package cn.dadongzicool.test;

import

public class Test
{
    public static void main(String args[]) throws IOException
    {
     @SuppressWarnings("unused")
    DrawImage image = new DrawImage();
    }
}



package cn.dadongzicool.test;

import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import
import

import javax.imageio.ImageIO;

public class DrawImage extends Frame implements Runnable{
   
    /**
     *
     */
    private static final long serialVersionUID = 1L;
   
    int x=0;
    int y=0;
    int dbx=0;
    int dby=-5;
    int bflag=0;
    int dx,dy,bx,by;
   
    int imgWidth,imgHeight;
   
    Image img;
    Graphics offScreenG;
    File file;
    BufferedImage bi;

    public DrawImage() throws IOException
    {
         super("DrawImage");
         setSize(350,350);
         setVisible(true);
         setResizable(false);

        Toolkit tk=Toolkit.getDefaultToolkit();
        img=tk.getImage("E:\\picture\\李静雯.jpg");
        
        file = new File("E:\\picture\\李静雯.jpg");
        bi = ImageIO.read(file);
        
        imgWidth = bi.getWidth();
        imgHeight = bi.getHeight();
        

        enableEvents(AWTEvent.KEY_EVENT_MASK);
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);

        new Thread(this).start();
    }
   
    public void processWindowEvent(WindowEvent e)
    {
        if(e.getID()==WindowEvent.WINDOW_CLOSING)
        {
            System.exit(0);
        }
    }
   
    public void processKeyEvent(KeyEvent e)
    {
        if(e.getID()==KeyEvent.KEY_PRESSED)
        {
            switch(e.getKeyCode())
            {
                case KeyEvent.VK_RIGHT:
                    dx=5;
                    dy=0;
                    break;
                case KeyEvent.VK_LEFT:
                    dx=-5;
                    dy=0;
                    break;
                case KeyEvent.VK_UP:
                    dx=0;
                    dy=-5;
                    break;
                case KeyEvent.VK_DOWN:
                    dx=0;
                    dy=5;
                    break;
                case KeyEvent.VK_SPACE:
                    dx=0;
                    dy=0;
                    bx=x+66;
                    by=y-5;
                    bflag=1;
                    break;
               default:
                    dx=0;
                    dy=0;

            }
            x=x+dx;
            y=y+dy;
        }
    }
    public void run()
    {
        while(true)
        {
            if(by<=0)
            {
                bflag=0;
            }
            if(bflag==1)
            {
                by=by+dby;
            }

            repaint();
            try
            {
               Thread.sleep(30);
            }catch(Exception e){}
        }
    }

    public void paint(Graphics g)
    {
        Image bufferPage = null;
        if(bufferPage==null)
        {
            bufferPage=createImage(350,350);
        }
        bufferPage.getGraphics();

        g.drawImage(img, x, y, this);
        g.fillRect(bx,by,5,7);
        g.setColor(Color.white);
        g.fillRect(bx, by+5,3,5);

        g.dispose();
        g.drawImage(bufferPage,getInsets().left,getInsets().top, this);
    }
    @Override
    public void update(Graphics g) {
            paint(g);
    }
}

本人出售软件专业毕业设计(包括论文,代码)题目众多,价格从优联系方式:QQ
1635008514(寻找高校代理)
2010-05-09 14:54
ck550114195
Rank: 1
来 自:河北邯郸
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-4-19
收藏
得分:0 
看着你这个有点头晕
2010-05-10 21:58
ck550114195
Rank: 1
来 自:河北邯郸
等 级:新手上路
帖 子:6
专家分:0
注 册:2010-4-19
收藏
得分:0 
回复 2楼 dadongzicool
明白了
2010-05-10 22:00
快速回复:我怎么取消不了闪烁
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017715 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved