u013922824 于 2014.04.26 09:31 提问

package two;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

import javax.swing.JFrame;

public class G1P2 extends JFrame{
final int WIDTH = 900,HEIGHT = 650;

``````double p1Speed = 0.5,p2Speed=0.5;
Rectangle left = new Rectangle(0,0,WIDTH/9,HEIGHT);
Rectangle right = new Rectangle((WIDTH/9)*9,0,WIDTH/9,HEIGHT);
Rectangle top  = new Rectangle(0,0,WIDTH,HEIGHT/9);
Rectangle bottom = new Rectangle(0,(HEIGHT/9)*9,(WIDTH/9)*10,HEIGHT/9);
Rectangle center = new Rectangle((int)((WIDTH/9)*2.5),(int)((HEIGHT/9)*2.5),(int)((WIDTH/9)*5),(HEIGHT/9)*4);

Rectangle obstacle = new Rectangle(WIDTH/2,(int)((HEIGHT/9)*7),WIDTH/10,HEIGHT/9);
Rectangle obstacle2 = new Rectangle(WIDTH/3,(int)((HEIGHT/9)*5),WIDTH/10,HEIGHT/4);
Rectangle obstacle3 = new Rectangle(2*(WIDTH/3),(int)((HEIGHT/9)*5),WIDTH/10,HEIGHT/4);
Rectangle obstacle4 = new Rectangle(WIDTH/3,(int)(HEIGHT/9),WIDTH/30,HEIGHT/9);
Rectangle obstacle5 = new Rectangle(WIDTH/2,(int)((HEIGHT/9)*1.5),WIDTH/30,HEIGHT/4);

Rectangle finish = new Rectangle(WIDTH/9,(HEIGHT/2)-HEIGHT/9,(int)((HEIGHT/9)*1.5),HEIGHT/70);

Rectangle p1 = new Rectangle(WIDTH/9,HEIGHT/2,WIDTH/30,WIDTH/30);
Rectangle p2 = new Rectangle(((WIDTH/9)+(int)((WIDTH/9)*1.5)/2),(HEIGHT/2)+(HEIGHT/10),WIDTH/30,WIDTH/30);

Rectangle lineO = new Rectangle(WIDTH/9,HEIGHT/2,(int)((WIDTH/9)*1.5)/2,HEIGHT/140);
Rectangle lineI = new Rectangle(((WIDTH/9)+((int)((WIDTH/9)*1.5)/2)),(HEIGHT/2)+(HEIGHT/10),(int)((WIDTH/9)*1.5)/2,HEIGHT/140);

public G1P2()
{
setSize(WIDTH/9*10,HEIGHT/9*10);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);

Move1  m1 = new Move1();
Move2 m2 = new Move2();
m1.start();
m2.start();

}
Image offScreenImage  = null;

public void paint(Graphics g)
{
super.paint(g);

g.setColor(Color.DARK_GRAY);
g.fillRect(0, 0, WIDTH, HEIGHT);

g.setColor(Color.GREEN);

g.fillRect(left.x, left.y, left.width, left.height);
g.fillRect(right.x, right.y, right.width, right.height);
g.fillRect(top.x, top.y, top.width, top.height);
g.fillRect(bottom.x, bottom.y, bottom.width, bottom.height);
g.fillRect(center.x, center.y, center.width, center.height);
g.fillRect(obstacle.x, obstacle.y, obstacle.width, obstacle.height);
g.fillRect(obstacle2.x, obstacle2.y, obstacle2.width, obstacle2.height);
g.fillRect(obstacle3.x, obstacle3.y, obstacle3.width, obstacle3.height);
g.fillRect(obstacle4.x, obstacle4.y, obstacle4.width, obstacle4.height);
g.fillRect(obstacle5.x, obstacle5.y, obstacle5.width, obstacle5.height);

g.setColor(Color.WHITE);
g.fillRect(lineO.x, lineO.y, lineO.width, lineO.height);
g.fillRect(lineI.x, lineI.y, lineI.width, lineI.height);

g.setColor(Color.YELLOW);
g.fillRect(finish.x, finish.y, finish.width, finish.height);

g.setColor(Color.BLUE);
g.fill3DRect(p1.x, p1.y, p1.width,p1.height,true);

g.setColor(Color.RED);
g.fill3DRect(p2.x, p2.y, p2.width, p2.height, true);
}

public void update(Graphics g)
{
if(offScreenImage == null){
offScreenImage = this.createImage(WIDTH, HEIGHT);
}
Graphics gOff = offScreenImage.getGraphics();
paint(gOff);
g.drawImage(offScreenImage, 0,0,null);
}

{
public void run()
{
while(true)
{
try {
repaint();
if(p1Speed<=5)
{
p1Speed +=0.2;
}
p1.y-=p1Speed;
} catch (Exception e) {
// TODO Auto-generated catch block
break;
}
}
}
}
{
public void run()
{
while(true)
{
try {
repaint();
if(p2Speed<=5)
{
p2Speed +=0.2;
}
p2.y-=p2Speed;
} catch (Exception e) {
// TODO Auto-generated catch block
break;
}
}
}
}
public static void main(String[] args) {
new G1P2();
}
``````

}

GDI+概述及双缓冲绘图技术
1.GDI概述及实例分析 1.1 GDI概述 GDI在全称是Graphics Device Interface，即图形设备接口。是图形显示与实际物理设备之间的桥梁。GDI使得用户无需关心具体设备的细节，而只需在一个虚拟的环境(即逻辑设备)中进行操作。它的桥梁作用体现在： (1)用户通过调用GDI函数将逻辑空间的操作转化为具体针对设备驱动程序的调用。 为实现图
VC双缓冲绘图技术介绍
VC双缓冲绘图技术介绍     双缓冲绘图，它是一种基本的图形图像绘图技术。首先，它在内存中创建一个与屏幕绘图区域一致的对象，然后将图形绘制到内存中的这个对象上，最后把这个对象上的图形数据一次性地拷贝并显示到屏幕上。这种技术能够大大地提高绘图的速度，减少卡顿和闪屏的问题。 我们为什么要使用双缓冲技术来进行绘图？     在应用程序开发中，当图像信息数据量很大时，绘图可能需要几秒钟甚至更长的时间

bitmap双缓冲技术-防止屏幕闪烁

Java中用双缓冲技术消除闪烁

Android学习笔记3-绘图，双缓冲机制

c++双缓冲技术绘图避免闪烁

JAVA中的双缓冲问题
/** *//** *双缓冲 *什么是重量级，轻量级 *轻量级在这里指用纯java实现的。重量级指和其他语言混合编程，这样耗用的资源多系统触发的绘画操作 *绘画操作的分类 *系统触发的和程序触发的绘画操作 *AWT的绘制与界面更新使用了一个单独的线程，称为AWT线程。这个线程可以在两种情形下更新显示。 *一种情况是界面“显露”，这可能会发生在界面首次显示时，或者界面某一部分由于被其它窗口遮盖后
Java双缓冲技术Java双缓冲技术
Java双缓冲技术Java双缓冲技术Java双缓冲技术Java双缓冲技术