赛车.java源代码 java 赛车游戏

java能做什么盘点十大惊艳Java应用程序
Java是一个十分伟大的语言和平台,可以编写出任何类型的应用 。它开放、快速、强大,可以运行在任意平台上 , 相比任何其它语言 , 它可以完成更多领域中应用程序的编写 , 本文将为大家介绍用Java编写的十大惊艳应用程序 。
10、无线传感器开发环境Sun SPOT
Sun SPOT设备是一个小巧的无线实验平台,通过电池供电 。它几乎完全以Java语言编写,通过它 , 普通程序员可以轻松创建那些以前需要专门嵌入式系统开发技巧的项目 。其硬件平台包含大量内置的传感器,可以轻松的与外部设备进行交互 。SPOT开发工具包含两个完整、不限距离的Sun SPOT(具有处理器、无线收发装置、传感器主板和电池)和一个基站Sun SPOT(具有处理器和无线收发装置) 。另外,还包含所有软件开发工具和在Sun SPOT上开始编写程序所需要的线缆 。
9、桌面辅助工具Project Looking Glass
Project Looking Glass是一个开源开发项目,从Sun公司的高级技术项目基础上演化而来 。通过它 , 无需对现有程序进行修改就可以让其运行在3D空间,同时还为3D窗口管理器和应用程序开发提供了应用程序编程接口(API) 。目前,它的现有应用集成功能只支持Solaris x86和Linux平台,不过,其3D应用程序开发库支持Linux、Solaris和Windows系统 。
8、Flying Saucer及Mozilla Rhino
Flying Saucer是一个百分之百的Java XHTM CSSIP渲染器,支持表分页(table pagination)、margin boxes、running elements和页面命名(named pages)等功能 。它兼容CSS 2.1(现在正进行兼容CSS 3的研发),可以嵌入到Swing应用程序中,它遵循开源LGPL许可协议 。这是一个令人印象非常深刻的程序库!同样令人印象深刻的还有Mozilla Rhino.Rhino是JavaScript的一个开源实现,完全用Java编写 。它一般被嵌入到Java应用程序中,以向终端用户提供脚本编写功能 。
7、DJ混音软件UltraMixer
UltraMixer是一个DJ混音软件,通过它你可以对不同格式的数码音乐进行实时混音,支持诸如MP3、WMA、AAC、OGG、WAV或CD等格式 。你只需要有一个声卡 。DJ的唱盘被两个数码音频播放器所取代 。目前有三个版本的UltraMixer:免费版、普通版和专业版 。它可以与众多硬件控制器实现交互,因此你不一定必须借助于鼠标进行操作 。
6、蓝光BD-J
蓝光光盘协会(Blu-ray Disc Association,BDA)选择了使用Java技术作为它们的高级交互应用规范的平台,原因如下:
·在移动领域和交互电视领域 , Java技术已经被证明是一个技术可靠的解决方案;
·在嵌入式设备中,Java技术已经被证明是一个跨平台的技术;
·Java技术可以为内容开发提供一个开放终端平台 , 同时具有安全的网络支持功能 。
在JavaOne大会上我们看到了令人印象深刻的BD-J.蓝光似乎已经赢得了标准之战 。现在或许可以购买蓝光播放器了 。
5、JavaFX Script及JavaFX Mobile
JavaFX Script是一个编译型、声明式脚本语言 , 不久将被加入到Java中,以使Java开发者和图形设计者创建富用户体验应用 。最近它增加了对关键帧动画功能的支持,还将针对Adobe Illustrator开发一个图形设计工具插件 。使用JavaFX Script编写的富互联网应用将作为一个applet运行在浏览器中 。
JavaFX Mobile是一个构建于Java技术和Linux开源技术之上完整的运行时环境 。JavaFX Mobile支持Java ME应用程序,另外 , 它还支持其它的标准Java API,因此可以支持众多新的和现有的Java应用 。JavaFX Mobile几乎将一个完整的Java SE环境移植到了手机设备上(去掉了诸如CORBA、JMX等功能) 。Sun进入富互联网应用开发市场虽然有些晚,不过它也有自己的优势 。
4、美国国家航空航天局的World Wind
World Wind让你可以从卫星上视角来查看地球上的任何地方 。与谷歌地图很相似,但是它完全使用Java编写,通过一个SDK,你可以将它嵌入到你的Java Swing应用中 。
3、办公软件ThinkFree
ThinkFree是微软Office的替代应用工具 。它包含ThinkFree Writer(文字处理)、ThinkFree Calc(电子表格)和ThinkFree Show(演示),让你可以创建、编辑和更新文档 。ThinkFree的界面、外观和操作习惯模仿微软的Office,可以大大减少用户的学习难度 。它只支持对PDF文件的处理 。
ThinkFree使用Java语言编写,因此它可以运行在Windows、Mac和Linux系统上 。目前还提供一个免费在线版,具有1GB存储空间,具有协作功能,可以发布到博客、网页或ThinkFree Docs.
2、模拟器JPC
JPC是一个纯正的Java模拟器 , 可以模拟具有完整虚拟外网设备的x86计算机 。它可以运行在任何支持JVM的硬件设备上,安全且稳定 。
JCP创建了一个虚拟的计算机,你可以通过一种灵活、安全和强大的方式来在上面安装自己喜欢的操作系统 。
1、Web流量分析工具Woopra
Woopra是当今世界上最全面、信息最丰富、最易于使用的实时Web流量分析工具 , 也是完全使用Java语言编写 。不过Woopra目前仍处于测试阶段,因此你可能会发现一些漏洞或缺少的功能,但是这个工具的前景非常不错 。
使用Java编写的精彩应用程序比比皆是 , 已经被广泛应用在各个领域 , 我们只是从中选取了10个 , 来证明Java语言的强大和普及 。
基于JAVA 的汽车租赁系统~~源代码~谢谢~高分~~!汽车租赁系统是汽车租赁公司的办公系统,包括从车辆的购置预算,审核购置,车辆预定,合同签订,车辆交接,收款结算,车辆维修,保险 , 违章车辆处置等业务 。汽车租赁系统是基于Internet互联网、ERP、GPS及数据库技术开发的软件,实现汽车租赁行业全业务流程的信息化,迪蒙汽车租赁解决方案是由迪蒙自主设计研发的一套多网融合汽车租赁管理整体解决方案 。
迪蒙汽车租赁系统软件后台由车辆信息管理、租赁业务管理、车辆服务管理、财务管理、客户管理、统计管理、线下门店管理和系统管理八大模块组成 。
1)、车辆信息管理
系统业务模块,包括车辆管理、租金设置、车辆调度和车辆优惠管理四大模块 。
2)、租赁业务管理
系统业务模块,包括汽车租赁业务设置、订单管理、车辆预定管理、订单变更管理、车辆续租管理、出/还车管理、押金管理、合同管理等各种业务管理功能 。
汽车租赁系统后台功能有哪些?
3)、车辆服务管理
车辆服务业务模块,包括保险管理、事故管理、违章管理、维修管理、保养管理、加油卡管理,这些主要
是租赁汽车的服务工作 。
4)、财务管理
对汽车租赁业务的辅助管理模块,也是不可缺少的模块,包括账单管理、发票管理、调账管理和资金明细
等功能 。
5)、客户管理
主要是针对客户信息的管理,包括个人客户管理、企业客户管理、黑名单管理、积分设置等功能 。
6)、统计管理
统计管理是统计站内的数据 , 包括用户统计、订单统计、成本统计、资金统计和车辆统计等 。
7)、线下门店管理
汽车租赁公司的另一辅助模快,包括系统用户管理、门店设置和员工管理 。
8)、系统管理
系统管理维护模块,包括站点管理、APP管理、基础设置、提醒管理 。
迪蒙汽车租赁解决方案融合了共享经济理念,通过先进的移动互联网技术,对传统汽车租赁系统进行了互联网化改造,不仅覆盖了传统租赁业务模式,还拓展了多元化的线上汽车租赁业务 。通过系统 , 客户不仅可以高效开展和管理线下业务,还可通过 PC 网站、APP 等渠道开展全新的线上租赁业务 。最大化优化配置时间与空间,提高汽车使用效率、提升用户体验、降低企业管理运营成本 , 助力企业“互联网”升级转型 。
怎么在电脑上运行Java源程序代码首先你要在你的电脑上安装jdk 。你可以在后面链接地址下载适合你自己的版本() , 如果这个链接过期了,请在这个首先找一找 。
在你的电脑上配置java环境变量,主要是配置path和classpath 。你可以百度java环境变量配置,可以找到很多java环境变量配置方法 。配置完毕 , 可以在cmd窗口下用java -version来查看是否配置成功 。如果显示出java版本相关的信息表示配置成功,可以进行下一步了 。
编译你的源代码 , cmd窗口下把路径改变(cd)到你源代码文件所在的路径,然后用javac 源文件名编译,例如javac Hello.java(需要注意的是源文件名需要是你文件public类的类名,如果你的文件有public类的话) 。当然你也可以不改变(cd)到源文件所在的路径,你的文件就需要加上绝对路径就可以了 。例如:javac e:\src\Hello.java.
运行你编译好的文件,java Hello(需要注意运行的时候没有后缀.java或者.class),同样你可以不改变路径用绝对路径运行 , 例如:java e:\src\Hello.如果你的代码中有窗口这样的类似的图形化界面,你就需要用javaw来运行 。
另外,你可以使用eclipse,NetBeans这样的集成开发环境(IDE)来写代码 , 这样方便很多 。
求一个JAVA的赛车游戏 真是点的这个还是要你自己去下载 。。。
可以是破解游戏?。。。?
推荐你去:塞班论坛 。。。找你自己的型号、希望可以找到你想要的!
塞班论坛注册后没有下载限制,所以是相当不错的哈!
求一个JAVA游戏代码?。。〖保 。。?/h2>俄罗斯方块——java源代码提供
import java.awt.*;
import java.awt.event.*;
//俄罗斯方块类
public class ERS_Block extends Frame{
public static boolean isPlay=false;
public static int level=1,score=0;
public static TextField scoreField,levelField;
public static MyTimer timer;
GameCanvas gameScr;
public static void main(String[] argus){
ERS_Block ers = new ERS_Block("俄罗斯方块游戏 V1.0 Author:Vincent");
WindowListener win_listener = new WinListener();
ers.addWindowListener(win_listener);
}
//俄罗斯方块类的构造方法
ERS_Block(String title){
super(title);
setSize(600,480);
setLayout(new GridLayout(1,2));
gameScr = new GameCanvas();
gameScr.addKeyListener(gameScr);
timer = new MyTimer(gameScr);
timer.setDaemon(true);
timer.start();
timer.suspend();
add(gameScr);
Panel rightScr = new Panel();
rightScr.setLayout(new GridLayout(2,1,0,30));
rightScr.setSize(120,500);
add(rightScr);
//右边信息窗体的布局
MyPanel infoScr = new MyPanel();
infoScr.setLayout(new GridLayout(4,1,0,5));
infoScr.setSize(120,300);
rightScr.add(infoScr);
//定义标签和初始值
Label scorep = new Label("分数:",Label.LEFT);
Label levelp = new Label("级数:",Label.LEFT);
scoreField = new TextField(8);
levelField = new TextField(8);
scoreField.setEditable(false);
levelField.setEditable(false);
infoScr.add(scorep);
infoScr.add(scoreField);
infoScr.add(levelp);
infoScr.add(levelField);
scorep.setSize(new Dimension(20,60));
scoreField.setSize(new Dimension(20,60));
levelp.setSize(new Dimension(20,60));
levelField.setSize(new Dimension(20,60));
scoreField.setText("0");
levelField.setText("1");
//右边控制按钮窗体的布局
MyPanel controlScr = new MyPanel();
controlScr.setLayout(new GridLayout(5,1,0,5));
rightScr.add(controlScr);
//定义按钮play
Button play_b = new Button("开始游戏");
play_b.setSize(new Dimension(50,200));
play_b.addActionListener(new Command(Command.button_play,gameScr));
//定义按钮Level UP
Button level_up_b = new Button("提高级数");
level_up_b.setSize(new Dimension(50,200));
level_up_b.addActionListener(new Command(Command.button_levelup,gameScr));
//定义按钮Level Down
Button level_down_b =new Button("降低级数");
level_down_b.setSize(new Dimension(50,200));
level_down_b.addActionListener(new Command(Command.button_leveldown,gameScr));
//定义按钮Level Pause
Button pause_b =new Button("游戏暂停");
pause_b.setSize(new Dimension(50,200));
pause_b.addActionListener(new Command(Command.button_pause,gameScr));
//定义按钮Quit
Button quit_b = new Button("退出游戏");
quit_b.setSize(new Dimension(50,200));
quit_b.addActionListener(new Command(Command.button_quit,gameScr));
controlScr.add(play_b);
controlScr.add(level_up_b);
controlScr.add(level_down_b);
controlScr.add(pause_b);
controlScr.add(quit_b);
setVisible(true);
gameScr.requestFocus();
}
}
//重写MyPanel类 , 使Panel的四周留空间
class MyPanel extends Panel{
public Insets getInsets(){
return new Insets(30,50,30,50);
}
}
//游戏画布类
class GameCanvas extends Canvas implements KeyListener{
final int unitSize = 30; //小方块边长
int rowNum; //正方格的行数
int columnNum; //正方格的列数
int maxAllowRowNum; //允许有多少行未削
int blockInitRow; //新出现块的起始行坐标
int blockInitCol; //新出现块的起始列坐标
int [][] scrArr; //屏幕数组
Block b; //对方快的引用
//画布类的构造方法
GameCanvas(){
rowNum = 15;
columnNum = 10;
maxAllowRowNum = rowNum - 2;
b = new Block(this);
blockInitRow = rowNum - 1;
blockInitCol = columnNum/2 - 2;
scrArr = new int [32][32];
}
//初始化屏幕,并将屏幕数组清零的方法
void initScr(){
for(int i=0;irowNum;i)
for (int j=0; jcolumnNum;j)
scrArr[j]=0;
b.reset();
repaint();
}
//重新刷新画布方法
public void paint(Graphics g){
for(int i = 0; irowNum; i)
for(int j = 0; jcolumnNum; j)
drawUnit(i,j,scrArr[j]);
}
//画方块的方法
public void drawUnit(int row,int col,int type){
scrArr[row][col] = type;
Graphics g = getGraphics();
tch(type){ //表示画方快的方法
case 0: g.setColor(Color.black);break; //以背景为颜色画
case 1: g.setColor(Color.blue);break; //画正在下落的方块
case 2: g.setColor(Color.magenta);break; //画已经落下的方法
}
g.fill3DRect(col*unitSize,getSize().height-(row 1)*unitSize,unitSize,unitSize,true);
g.dispose();
}
public Block getBlock(){
return b; //返回block实例的引用
}
//返回屏幕数组中(row,col)位置的属性值
public int getScrArrXY(int row,int col){
if (row0 || row = rowNum || col0 || col = columnNum)
return(-1);
else
return(scrArr[row][col]);
}
//返回新块的初始行坐标方法
public int getInitRow(){
return(blockInitRow); //返回新块的初始行坐标
}
//返回新块的初始列坐标方法
public int getInitCol(){
return(blockInitCol); //返回新块的初始列坐标
}
//满行删除方法
void deleteFullLine(){
int full_line_num = 0;
int k = 0;
for (int i=0;irowNum;i){
boolean isfull = true;
L1:for(int j=0;jcolumnNum;j)
if(scrArr[j] == 0){
k;
isfull = false;
break L1;
}
if(isfull) full_line_num;
if(k!=0k-1!=i!isfull)
for(int j = 0; jcolumnNum; j){
if (scrArr[j] == 0)
drawUnit(k-1,j,0);
else
drawUnit(k-1,j,2);
scrArr[k-1][j] = scrArr[j];
}
}
for(int i = k-1 ;irowNum; i){
for(int j = 0; jcolumnNum; j){
drawUnit(i,j,0);
scrArr[j]=0;
}
}
ERS_Block.score= full_line_num;
ERS_Block.scoreField.setText("" ERS_Block.score);
}
//判断游戏是否结束方法
boolean isGameEnd(){
for (int col = 0 ; col columnNum; col){
if(scrArr[maxAllowRowNum][col] !=0)
return true;
}
return false;
}
public void keyTyped(KeyEvent e){
}
public void keyReleased(KeyEvent e){
}
//处理键盘输入的方法
public void keyPressed(KeyEvent e){
if(!ERS_Block.isPlay)
return;
tch(e.getKeyCode()){
case KeyEvent.VK_DOWN:b.fallDown();break;
case KeyEvent.VK_LEFT:b.leftMove();break;
case KeyEvent.VK_RIGHT:b.rightMove();break;
case KeyEvent.VK_SPACE:b.leftTurn();break;
}
}
}
//处理控制类
class Command implements ActionListener{
static final int button_play = 1; //给按钮分配编号
static final int button_levelup = 2;
static final int button_leveldown = 3;
static final int button_quit = 4;
static final int button_pause = 5;
static boolean pause_resume = true;
int curButton; //当前按钮
GameCanvas scr;
//控制按钮类的构造方法
Command(int button,GameCanvas scr){
curButton = button;
this.scr=scr;
}
//按钮执行方法
public void actionPerformed (ActionEvent e){
tch(curButton){
case button_play:if(!ERS_Block.isPlay){
scr.initScr();
ERS_Block.isPlay = true;
ERS_Block.score = 0;
ERS_Block.scoreField.setText("0");
ERS_Block.timer.resume();
}
scr.requestFocus();
break;
case button_levelup:if(ERS_Block.level10){
ERS_Block.level;
ERS_Block.levelField.setText("" ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText("" ERS_Block.score);
}
scr.requestFocus();
break;
case button_leveldown:if(ERS_Block.level1){
ERS_Block.level--;
ERS_Block.levelField.setText("" ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText("" ERS_Block.score);
}
scr.requestFocus();
break;
case button_pause:if(pause_resume){
ERS_Block.timer.suspend();
pause_resume = false;
}else{
ERS_Block.timer.resume();
pause_resume = true;
}
scr.requestFocus();
break;
case button_quit:System.exit(0);
}
}
}
//方块类
class Block {
static int[][] pattern = {
{0x0f00,0x4444,0x0f00,0x4444},//用十六进至表示,本行表示长条四种状态
{0x04e0,0x0464,0x00e4,0x04c4},
{0x4620,0x6c00,0x4620,0x6c00},
{0x2640,0xc600,0x2640,0xc600},
{0x6220,0x1700,0x2230,0x0740},
{0x6440,0x0e20,0x44c0,0x8e00},
{0x0660,0x0660,0x0660,0x0660}
};
int blockType; //块的模式号(0-6)
int turnState; //块的翻转状态(0-3)
int blockState; //快的下落状态
int row,col; //块在画布上的坐标
GameCanvas scr;
//块类的构造方法
Block(GameCanvas scr){
this.scr = scr;
blockType = (int)(Math.random() * 1000)%7;
turnState = (int)(Math.random() * 1000)%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
}
//重新初始化块,并显示新块
public void reset(){
blockType = (int)(Math.random() * 1000)%7;
turnState = (int)(Math.random() * 1000)%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
dispBlock(1);
}
//实现“块”翻转的方法
public void leftTurn(){
if(assertValid(blockType,(turnState1)%4,row,col)){
dispBlock(0);
turnState = (turnState1)%4;
dispBlock(1);
}
}
//实现“块”的左移的方法
public void leftMove(){
if(assertValid(blockType,turnState,row,col-1)){
dispBlock(0);
col--;
dispBlock(1);
}
}
//实现块的右移
public void rightMove(){
if(assertValid(blockType,turnState,row,col 1)){
dispBlock(0);
col;
dispBlock(1);
}
}
//实现块落下的操作的方法
public boolean fallDown(){
if(blockState == 2)
return(false);
if(assertValid(blockType,turnState,row-1,col)){
dispBlock(0);
row--;
dispBlock(1);
return(true);
}else{
blockState = 2;
dispBlock(2);
return(false);
}
}
//判断是否正确的方法
boolean assertValid(int t,int s,int row,int col){
int k = 0x8000;
for(int i = 0; i4; i){
for(int j = 0; j4; j){
if((int)(pattern[t][s]k) != 0){
int temp = scr.getScrArrXY(row-i,col j);
if (temp0||temp==2)
return false;
}
k = k1;
}
}
return true;
}
//同步显示的方法
public synchronized void dispBlock(int s){
int k = 0x8000;
for (int i = 0; i4; i){
for(int j = 0; j4; j){
if(((int)pattern[blockType][turnState]k) != 0){
scr.drawUnit(row-i,col j,s);
}
k=k1;
}
}
}
}
//定时线程
class MyTimer extends Thread{
GameCanvas scr;
public MyTimer(GameCanvas scr){
this.scr = scr;
}
public void run(){
while(true){
try{
sleep((10-ERS_Block.level1)*100);
}
catch(InterruptedException e){}
if(!scr.getBlock().fallDown()){
scr.deleteFullLine();
if(scr.isGameEnd()){
ERS_Block.isPlay = false;
suspend();
}else
scr.getBlock().reset();
}
}
}
class WinListener extends WindowAdapter{
public void windowClosing (WindowEvent l){
System.exit(0);
}
}
求java小游戏源代码表1. CheckerDrag.java
// CheckerDrag.javaimport java.awt.*;import java.awt.event.*;public class CheckerDrag extends java.applet.Applet{// Dimension of checkerboard square.// 棋盘上每个小方格的尺寸final static int SQUAREDIM = 40;// Dimension of checkerboard -- includes black outline.// 棋盘的尺寸 – 包括黑色的轮廓线final static int BOARDDIM = 8 * SQUAREDIM2;// Dimension of checker -- 3/4 the dimension of a square.// 棋子的尺寸 – 方格尺寸的3/4final static int CHECKERDIM = 3 * SQUAREDIM / 4;// Square colors are dark green or white.// 方格的颜色为深绿色或者白色final static Color darkGreen = new Color (0, 128, 0);// Dragging flag -- set to true when user presses mouse button over checker// and cleared to false when user releases mouse button.// 拖动标记 --当用户在棋子上按下鼠标按键时设为true,// 释放鼠标按键时设为falseboolean inDrag = false;// Left coordinate of checkerboard's upper-left corner.// 棋盘左上角的左方向坐标int boardx;// Top coordinate of checkerboard's upper-left corner.//棋盘左上角的上方向坐标int boardy;// Left coordinate of checker rectangle origin (upper-left corner).// 棋子矩形原点(左上角)的左方向坐标int ox;// Top coordinate of checker rectangle origin (upper-left corner).// 棋子矩形原点(左上角)的上方向坐标int oy;// Left displacement between mouse coordinates at time of press and checker// rectangle origin.// 在按键时的鼠标坐标与棋子矩形原点之间的左方向位移int relx;// Top displacement between mouse coordinates at time of press and checker// rectangle origin.// 在按键时的鼠标坐标与棋子矩形原点之间的上方向位移int rely;// Width of applet drawing area.// applet绘图区域的宽度int width;// Height of applet drawing area.// applet绘图区域的高度int height;// Image buffer.// 图像缓冲Image imBuffer;// Graphics context associated with image buffer.// 图像缓冲相关联的图形背景Graphics imG;public void init (){// Obtain the size of the applet's drawing area.// 获取applet绘图区域的尺寸width = getSize ().width;height = getSize ().height;// Create image buffer.// 创建图像缓冲imBuffer = createImage (width, height);// Retrieve graphics context associated with image buffer.// 取出图像缓冲相关联的图形背景imG = imBuffer.getGraphics ();// Initialize checkerboard's origin, so that board is centered.// 初始化棋盘的原点,使棋盘在屏幕上居中boardx = (width - BOARDDIM) / 21;boardy = (height - BOARDDIM) / 21;// Initialize checker's rectangle's starting origin so that checker is// centered in the square located in the top row and second column from// the left.// 初始化棋子矩形的起始原点,使得棋子在第一行左数第二列的方格里居中ox = boardxSQUAREDIM(SQUAREDIM - CHECKERDIM) / 21;oy = boardy(SQUAREDIM - CHECKERDIM) / 21;// Attach a mouse listener to the applet. That listener listens for// mouse-button press and mouse-button release events.// 向applet添加一个用来监听鼠标按键的按下和释放事件的鼠标监听器addMouseListener (new MouseAdapter (){public void mousePressed (MouseEvent e){// Obtain mouse coordinates at time of press.// 获取按键时的鼠标坐标int x = e.getX ();int y = e.getY ();// If mouse is over draggable checker at time// of press (i.e., contains (x, y) returns// true), save distance between current mouse// coordinates and draggable checker origin// (which will always be positive) and set drag// flag to true (to indicate drag in progress).// 在按键时如果鼠标位于可拖动的棋子上方// (也就是contains (x, y)返回true),则保存当前// 鼠标坐标与棋子的原点之间的距离(始终为正值)并且// 将拖动标志设为true(用来表明正处在拖动过程中)if (contains (x, y)){relx = x - ox;rely = y - oy;inDrag = true;}}boolean contains (int x, int y){// Calculate center of draggable checker.// 计算棋子的中心位置int cox = oxCHECKERDIM / 2;int coy = oyCHECKERDIM / 2;// Return true if (x, y) locates with bounds// of draggable checker. CHECKERDIM / 2 is the// radius.// 如果(x, y)仍处于棋子范围内则返回true// CHECKERDIM / 2为半径return (cox - x) * (cox - x)(coy - y) * (coy - y)CHECKERDIM / 2 * CHECKERDIM / 2;}public void mouseReleased (MouseEvent e){// When mouse is released, clear inDrag (to// indicate no drag in progress) if inDrag is// already set.// 当鼠标按键被释放时 , 如果inDrag已经为true,// 则将其置为false(用来表明不在拖动过程中)if (inDrag)inDrag = false;}});// Attach a mouse motion listener to the applet. That listener listens// for mouse drag events.//向applet添加一个用来监听鼠标拖动事件的鼠标运动监听器addMouseMotionListener (new MouseMotionAdapter (){public void mouseDragged (MouseEvent e){if (inDrag){// Calculate draggable checker's new// origin (the upper-left corner of// the checker rectangle).// 计算棋子新的原点(棋子矩形的左上角)int tmpox = e.getX () - relx;int tmpoy = e.getY () - rely;// If the checker is not being moved// (at least partly) off board,// assign the previously calculated// origin (tmpox, tmpoy) as the// permanent origin (ox, oy), and// redraw the display area (with the// draggable checker at the new// coordinates).// 如果棋子(至少是棋子的一部分)没有被// 移出棋盘 , 则将之前计算的原点// (tmpox, tmpoy)赋值给永久性的原点(ox, oy),// 并且刷新显示区域(此时的棋子已经位于新坐标上)if (tmpoxboardxtmpoyboardytmpoxCHECKERDIMboardxBOARDDIMtmpoyCHECKERDIMboardyBOARDDIM){ox = tmpox;oy = tmpoy;repaint ();}}}});}public void paint (Graphics g){// Paint the checkerboard over which the checker will be dragged.// 在棋子将要被拖动的位置上绘制棋盘paintCheckerBoard (imG, boardx, boardy);// Paint the checker that will be dragged.// 绘制即将被拖动的棋子paintChecker (imG, ox, oy);// Draw contents of image buffer.// 绘制图像缓冲的内容g.drawImage (imBuffer, 0, 0, this);}void paintChecker (Graphics g, int x, int y){// Set checker shadow color.// 设置棋子阴影的颜色g.setColor (Color.black);// Paint checker shadow.// 绘制棋子的阴影g.fillOval (x, y, CHECKERDIM, CHECKERDIM);// Set checker color.// 设置棋子颜色g.setColor (Color.red);// Paint checker.// 绘制棋子g.fillOval (x, y, CHECKERDIM - CHECKERDIM / 13, CHECKERDIM - CHECKERDIM / 13);}void paintCheckerBoard (Graphics g, int x, int y){// Paint checkerboard outline.// 绘制棋盘轮廓线g.setColor (Color.black);g.drawRect (x, y, 8 * SQUAREDIM1, 8 * SQUAREDIM1);// Paint checkerboard.// 绘制棋盘for (int row = 0; row8; row){g.setColor (((row1) != 0) ? darkGreen : Color.white);for (int col = 0; col8; col){g.fillRect (x1col * SQUAREDIM, y1row * SQUAREDIM,SQUAREDIM, SQUAREDIM);g.setColor ((g.getColor () == darkGreen) ? Color.white :darkGreen);}}}// The AWT invokes the update() method in response to the repaint() method// calls that are made as a checker is dragged. The default implementation// of this method, which is inherited from the Container class, clears the// applet's drawing area to the background color prior to calling paint().// This clearing followed by drawing causes flicker. CheckerDrag overrides// update() to prevent the background from being cleared, which eliminates// the flicker.// AWT调用了update()方法来响应拖动棋子时所调用的repaint()方法 。该方法从// Container类继承的默认实现会在调用paint()之前 , 将applet的绘图区域清除// 为背景色,这种绘制之后的清除就导致了闪烁 。CheckerDrag重写了update()来// 防止背景被清除,从而消除了闪烁 。public void update (Graphics g){paint (g);}}
【赛车.java源代码 java 赛车游戏】赛车.java源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于java 赛车游戏、赛车.java源代码的信息别忘了在本站进行查找喔 。

    推荐阅读