java游戏源代码意思 java经典游戏源码

基于Java语言的打地鼠的小游戏源代码是什么? public void mouseClicked(MouseEvent e){\x0d\x0aObject source=e.getSource();//获取事件源java游戏源代码意思,即地鼠标签\x0d\x0aif(source instanceof JLabel){//如果事件是标签组件\x0d\x0aJLabel mouse=(JLabel)source;//强制转换为JLabel标签\x0d\x0amouse.setIcon(null);//取消标签图标\x0d\x0a}\x0d\x0a}\x0d\x0a});\x0d\x0athis.getContentPane().add(mouses[i]);//添加显示地鼠java游戏源代码意思的标签到窗体\x0d\x0a}\x0d\x0a\x0d\x0amouses[0].setLocation(253, 300);//设置每个标签java游戏源代码意思的位置\x0d\x0amouses[1].setLocation(333, 250);\x0d\x0amouses[2].setLocation(388, 296);\x0d\x0amouses[3].setLocation(362, 364);\x0d\x0amouses[4].setLocation(189, 353);\x0d\x0amouses[5].setLocation(240, 409);\x0d\x0a\x0d\x0afinal JLabel backLabel=new JLabel();//创建显示背景java游戏源代码意思的标签\x0d\x0abackLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());\x0d\x0athis.setBounds(100,100,img.getIconWidth(),img.getIconHeight());\x0d\x0abackLabel.setIcon(img);//添加背景到标签\x0d\x0athis.getContentPane().add(backLabel);//添加背景标签到窗体\x0d\x0a}\x0d\x0a/**\x0d\x0a* 线程的核心方法\x0d\x0a*/\x0d\x0a\x0d\x0apublic void run(){\x0d\x0awhile(true){//使用无限循环\x0d\x0atry{\x0d\x0aThread.sleep(3000);//使线程休眠3秒\x0d\x0aint index=(int)(Math.random()*6);//生成随机的地鼠索引\x0d\x0aif(mouses[index].getIcon()==null){//如果地鼠标签没有设置图片\x0d\x0amouses[index].setIcon(imgMouse);//为该标签添加地鼠图片\x0d\x0a}\x0d\x0a}catch(InterruptedException e){\x0d\x0ae.printStackTrace();\x0d\x0a}\x0d\x0a}\x0d\x0a}\x0d\x0a\x0d\x0a}
求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);}}
悬赏100元钱 。注释一个java扫雷游戏源代码,就是把每行的意思写到后面就可以了!在线等 。import java.awt.*;
import javax.swing.*;
import java.util.Random;
import java.awt.event.*;
class Min extends JPanel//雷的类
{
//备注:鼠标的左键 = 1;右键 = 3;中键 = 2
private int flag = 0,statu = 0; //定义雷的属性 0:没有打开 1:打开 2:标示为雷 3:不确定
//flag = 0 不是雷; flag = 1是雷
private int but,count = 0; //but:哪一个鼠标键被按下去了count:这个区域周围有多少个雷
private int mx = 0,my = 0,mw = 10; //定义雷的坐标和宽度
public Min()//构造函数
{
statu = 0;
}
public Min(int f,int x,int y,int w)
//构造函数
{
flag = f;
mx= x;
my= y;
mw= w;
}
public int getFlag(){return flag;}
public int getStatu(){return statu;}
public int getMx(){return mx;}
public int getMy(){return my;}
public int getMw(){return mw;}
public int getCount(){return count;}
public void setFlag(int f){flag = f;}
public void setCount(int c){count = c;}
public void setData(int f,int x,int y,int w,int s)
//传递值
{
flag = f;
mx= (x-1)*w;
my= (y-1)*w;
mw= w-1;
statu = s;
}
//根据你点击鼠标的不同来改变雷的属性
public int sendKey(int key)
{
//返回值,如果游戏结束则返回-1
int rtn = 1;
if(key == 3)
{
switch(statu)
{
case 1:
break;
case 2:
statu = 3;
break;
case 3:
statu = 0;
break;
case 0:
statu = 2;
break;
}
rtn = 1;
}
if(key == 1statu == 0)
{
switch(flag)
{
case 0:
statu = 1;
rtn = 2;
break;
case 1:
statu = 1;
rtn = -1;
break;
}
}
return rtn;
}
}
class DrawPanel extends JPanel
{
private int i,j;
private int f = 0;//if f = 1 then game over ,if f =2 then win
private int chx = 0,chy = 0; //专门记录坐标x,y的值
private int msum = 6,ksum = 0; //msum:雷的个数,ksum:标示雷的个数
private int bx = 10,by = 10,bw = 40; //bx,by:棋盘的大小,bw:棋子的大小
public Min board[][] = {
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
{new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min(),new Min()},
};
// 画坐标为ax,ay区域的雷的状态
public void draw(Graphics g,int ax,int ay)
{
int x,y,w; // 坐标x,y;和宽度:w
int s,c,flag; //状态;雷的个数;
int cx = bw/2 - 4;
int cy = bw/24;
x = board[ax][ay].getMx();
y = board[ax][ay].getMy();
w = board[ax][ay].getMw();
s = board[ax][ay].getStatu();
c = board[ax][ay].getCount();
flag= board[ax][ay].getFlag();
switch(s)
{
case 0: //没有打开状态
{
g.setColor(Color.black);
g.fillRect(x,y,w,w);
break;
}
case 1: //打开状态
{
g.setColor(Color.blue);
g.fillRect(x,y,w,w);
if(c != 0flag == 0) //此处没有雷
{
g.setColor(Color.red);
g.drawString(String.valueOf(c),xcx,ycy);
}
if(flag == 1) //此处有雷
{
g.setColor(Color.red);
g.fillRect(x,y,w,w);
g.setColor(Color.blue);
g.drawString(" 雷",xcx,ycy);
}
break;
}
case 2: //标雷状态
{
g.setColor(Color.green);
g.fillRect(x,y,w,w);
g.setColor(Color.blue);
g.drawString(" 旗",xcx,ycy);
break;
}
case 3: //不确定状态
{
g.setColor(Color.black);
g.fillRect(x,y,w,w);
g.setColor(Color.red);
g.drawString("?",xcx,ycy);
break;
}
default:
break;
}
}
// 没有图形器的绘图函数:画出坐标ax,ay的雷的状态和图形
public void draw(int ax,int ay)
{
Graphics g;
g = this.getGraphics();
draw(g,ax,ay);
}
//打开周围没有雷的地方,并且绘画所在区域点击左键触发
public int openNoMin(int ax,int ay)
{
int i,j;
if(ax1||ay1||axbx||ayby) return 0;//鼠标点击的区域出界了
if(board[ax][ay].getStatu() != 0) return 0;//如果此区域打开了,返回
board[ax][ay].sendKey(1); //如果返回值等于-1,就说明游戏结束
draw(ax,ay);
if(board[ax][ay].getFlag() == 1)
//如果游戏结束 , 把所有的雷都显示出来
{
for(i = 1;i=bx;i)
{
for(j = 1;j = by;j)
{
if(board[i][j].getFlag() == 1)
{
board[i][j].sendKey(1);
draw(i,j);
}
}
}
return -1;
}
//如果游戏没有结束
if(board[ax][ay].getCount()0)
{
ksum;
return 1; //周围有雷 , 就不用打开周围地区
}
if(board[ax][ay].getCount() == 0board[ax][ay].getFlag() == 0)
//周围没有雷,打开周围地区,直到有雷的地区
{
openNoMin(ax-1,ay-1);openNoMin(ax,ay-1);openNoMin(ax 1,ay-1);
openNoMin(ax-1,ay);openNoMin(ax 1,ay);
openNoMin(ax-1,ay 1);openNoMin(ax,ay 1);openNoMin(ax 1,ay 1);
}
ksum;
return 1;
}
//计算坐标x,y的周围雷的个数
public int getCount(int ai,int aj)
{
int sum = 0;
if(board[ai][aj].getFlag() == 1)
{
return sum;
}
if(ai1aj1aibxajby)
{
sum =board[ai-1][aj-1].getFlag()board[ai][aj-1].getFlag()board[ai 1][aj-1].getFlag()
board[ai-1][aj].getFlag()board[ai 1][aj].getFlag()
board[ai-1][aj 1].getFlag()board[ai][aj 1].getFlag()board[ai 1][aj 1].getFlag();
}
if(ai==1aj==1)
{
sum =board[ai 1][aj].getFlag()
board[ai][aj 1].getFlag()board[ai 1][aj 1].getFlag();
}
if(ai==1aj==by)
{
sum =board[ai][aj-1].getFlag()board[ai 1][aj-1].getFlag()
board[ai 1][aj].getFlag();
}
if(ai==bxaj==1)
{
sum =board[ai-1][aj].getFlag()
board[ai-1][aj 1].getFlag()board[ai][aj 1].getFlag();
}
if(ai==bxaj==by)
{
sum =board[ai-1][aj-1].getFlag()board[ai][aj-1].getFlag()
board[ai-1][aj].getFlag();
}
if(ai==1aj1ajby)
{
sum =board[ai][aj-1].getFlag()board[ai 1][aj-1].getFlag()
board[ai 1][aj].getFlag()
board[ai][aj 1].getFlag()board[ai 1][aj 1].getFlag();
}
if(ai==bxaj1ajby)
{
sum =board[ai-1][aj-1].getFlag()board[ai][aj-1].getFlag()
board[ai-1][aj].getFlag()
board[ai-1][aj 1].getFlag()board[ai][aj 1].getFlag();
}
if(ai1aibxaj==1)
{
sum =board[ai-1][aj].getFlag()board[ai 1][aj].getFlag()
board[ai-1][aj 1].getFlag()board[ai][aj 1].getFlag()board[ai 1][aj 1].getFlag();
}
if(ai1aibxaj==by)
{
sum =board[ai-1][aj-1].getFlag()board[ai][aj-1].getFlag()board[ai 1][aj-1].getFlag()
board[ai-1][aj].getFlag()board[ai 1][aj].getFlag();
}
return sum;
}
// 传入参数:几列,几行,宽度 , 雷数
public void initMin(int ax,int ay,int aw,int as)
{
int k = 1;//表明产生的第几个雷
Random r;//随机数
f = 0;//f=0表示游戏还没有结束
ksum = 0;
bx = ax;
by = ay;
bw = aw;
msum = as;
r = new Random();
//初始化底盘的值
for(i = 1;i = bx;i)
{
for(j=1;j=by;j)
{
board[i][j].setData(0,i,j,bw,0);
}
}
// 随机产生雷
while(k = msum)
{
i = r.nextInt(bx) 1;
j = r.nextInt(by) 1;
if(board[i][j].getFlag() != 1)
{
board[i][j].setFlag(1);
k;
}
}
// 非雷区的周围有几个雷,初始化其值
for(i = 1;i = bx;i)
{
for(j=1;j=by;j)
{
board[i][j].setCount(getCount(i,j));
}
}
setBackground(Color.white);
repaint();
}
// 构造函数
public DrawPanel(int ax,int ay,int aw,int as)
{
initMin(ax,ay,aw,as);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
int r;
if(f != 0) return;//如果游戏结束,返回
chx= me.getX();
chy= me.getY();
if(me.getButton() != 1)
{
board[chx/bw 1][chy/bw 1].sendKey(me.getButton());
draw(chx/bw 1,chy/bw 1);
}
else if(me.getButton() == 1)
{
if(openNoMin(chx/bw 1,chy/bw 1) == -1)
{
f = 1;
repaint();
}
else if ( ksummsum == bx*by )
{
f = 2;
repaint();
}
}
}
}
);
}
// 重画所有的图形 , 包括一些修饰的图形
public void paint(Graphics g)
{
int x,y,w;
int s;
【java游戏源代码意思 java经典游戏源码】int cx = bw/2 - 4;
int cy = bw/24;
g.clearRect(0,0,600,600);
for(i=1;i=bx;i)
{
for(j=1;j=by;j)
{
draw(g,i,j);
}
}
if(f == 1)
{
Font f = new Font("11",1,70);
Font fo = g.getFont();
g.setColor(Color.white);
g.setFont(f);
//g.setSize();
g.drawString("Game Over",0,200);
g.setFont(fo);
}
if( f == 2 )
{
Font f = new Font("11",1,70);
Font fo = g.getFont();
g.setColor(Color.white);
g.setFont(f);
//g.setSize();
g.drawString("You win!",0,200);
g.setFont(fo);
}
}
};
// 主类和程序的入口
public class Mine extends JFrame implements ActionListener
{
Containercp = getContentPane();
JButtonbt = new JButton("开局");
Label l1 = new Label("列:");
Label l2 = new Label("行:");
Label l3 = new Label("宽度:");
Label l4 = new Label("雷的个数:");
TextField tf1 = new TextField("10",2); //列
TextField tf2 = new TextField("10",2); //行
TextField tf3 = new TextField("40",2); //宽度
TextField tf4 = new TextField("15",2); //雷的个数
int x=10,y=10,w=40,sum=15;
DrawPaneldp = new DrawPanel(x,y,w,sum);
public Mine()
{
setBackground(Color.white);
cp.setLayout(null);
cp.add(dp);
cp.add(bt);
cp.add(tf1);
cp.add(tf2);
cp.add(tf3);
cp.add(tf4);
cp.add(l1);
cp.add(l2);
cp.add(l3);
cp.add(l4);
l1.setBounds(20 ,10,20,20);
tf1.setBounds(40,10,20,20);
l2.setBounds(70,10,20,20);
tf2.setBounds(90,10,20,20);
l3.setBounds(120,10,40,20);
tf3.setBounds(160,10,20,20);
l4.setBounds(190,10,60,20);
tf4.setBounds(250,10,20,20);
bt.setBounds(300,10,80,20);
dp.setBounds(20,40,x*w,y*w);
setResizable(false);
setSize(x*w 40,y*w 80);
setTitle(" 扫雷");
show();
bt.addActionListener(this);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{System.exit(0);}
}
);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == bt)
{
//x = Integer.parseInt(tf1.getText());
//y = Integer.parseInt(tf2.getText());
//w = Integer.parseInt(tf3.getText());
sum = Integer.parseInt(tf4.getText());
setSize(x*w 40,y*w 80);
dp.setBounds(20,40,x*w,y*w);
show();
dp.initMin(x,y,w,sum);
}
}
public static void main(String args[])
{
new Mine();
}
};
Java里的字节码和源代码分别啥意思,和起到什么左右/*java是一门高级编程语言java游戏源代码意思 , 是用来写程序代码的 。
用java写的文本(字符串序列)就是源代码 。
计算机不能直接执行源代码java游戏源代码意思,必须用一个叫编译器的程序(javac.exe)将源代码
翻译成字节码java游戏源代码意思,然后让一个叫解释器的程序(java.exe)去执行字节码java游戏源代码意思,即运行程序 。
下面的就是一个小程序的源代码,功能是输出九九乘法表 。
下图中的Test.class就是这个源代码文件翻译后的由字节码组成的文件 。
而最下面的那个黑框就是程序执行后的结果 。
java Test就是在执行Test.class字节码文件,即运行这个程序 。
*/
//这下面的就是源代码
public class Test {
public static void main(String[] args) {
int i,j;
for(i=1;i=9;i) {
for(j=1;j=i;j)
System.out.printf("%dx%d=%-4d",j,i,j*i);
System.out.println();
}
}
}
源代码究竟是什么?源代码就是人类可以看懂的机器文字,程序员在写完代码以后,会将源代码编译为机器代码,可能是一个可执行程序exe啥的,我们平时用的就是这个可执行程序,要想增加功能,或者改善程序,就需要有源代码了,因为人不可能通过0和1编出高级程序 。
举个例子:你用Word写好一个文档 , 生成一个PDF文件,一般来说PDF是不可修改的,你可以把这个PDF发给别人阅读,但是别人要想修改这个PDF就不好操作 。而你有这个PDF的原稿(Word文档)你可以很方便的修改然后再生成PDF文档 。这里的Word文档就相当于源代码,PDF文档就相当于软件 。
简介
代码,没什么可说的,广义的,只要算是程序语言写的都是,c写出来的是代码,编译后,成汇编语言程序,也可以说是代码;再汇编成,机器语言程序,也可以说是代码;不过,算得上代码的,也算是程序,一般都是广义的说法 。
说“源”的问题、你用c写出来的,让我看 , 那是源代码;你把编译成.exe文件的代码,让我直接运行,那就不是源代码、你做的java游戏,如果你把自己写的java代码给我,那是源代码;把处理过的可执行文件给我 , 那不是源代码 。
java游戏源代码意思的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于java经典游戏源码、java游戏源代码意思的信息别忘了在本站进行查找喔 。

    推荐阅读