别踩白块java程序代码 别踩白块编程-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

别踩白块java程序代码 别踩白块编程

JAVA别踩白块怎么让一行除了黑块其他都是白块

import java.awt.Color;import java.awt.GridLayout;import javax.swing.JButton;import javax.swing.JFrame; public class MiGong extends JFrame{ private static final long serialVersionUID = 1L; private static final int ROW = 8; private static final int COL = 9; int[][] map = { {2,0,1,0,0,0,1,0}, {0,0,1,0,0,0,1,0}, {0,0,1,0,1,1,0,0}, {0,1,1,1,0,0,0,0}, {0,0,0,1,0,0,0,0}, {0,1,0,0,0,1,0,1}, {0,1,1,1,1,0,0,1}, {1,1,0,0,0,1,0,1}, {1,1,0,0,0,0,0,3} }; public static void main ( String args[] ) { new MiGong (); } public MiGong () { setTitle ("迷宫"); setLayout (new GridLayout (ROW, COL, 0, 0)); for ( int h = 0; h COL; h++ ) { for ( int g = 0; g ROW; g++ ) { switch (map[h][g]) { case 0: JButton p = new JButton (); p.setBackground (Color.red); add (p); break; case 1: JButton q = new JButton (); q.setBackground (Color.blue); add (q); break; case 2: JButton m = new JButton ("入口"); m.setBackground (Color.green); add (m); break; case 3: JButton n = new JButton ("出口"); n.setBackground (Color.green); add (n); break; } } } pack (); setLocationRelativeTo (null); setDefaultCloseOperation (EXIT_ON_CLOSE); setVisible (true); }}

创新互联专注于五峰企业网站建设,成都响应式网站建设公司,成都商城网站开发。五峰网站建设公司,为五峰等地区提供建站服务。全流程按需开发,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

java初学者如何编写别踩黑白块,求编写内容 在eclipse里,是要有图形用户界面的,别乱复制

小弟啊,看来你真的是初学啊,抽象类Friut定义在哪个包中都可以,但是在它的子类中要导入,importFruit这个类,然后在Fruit这个类中定义一个抽象方法harvest(),不做任何实现就可以啦

JAVA中为什么画出的图形没法显示出来?

你这个是代码里面拼写错误了,改成下面的可以显示

class DontStepOnWhitePiece extends JPanel

{

public void paint(Graphics g)   //上面的这里拼写错误,panit

{

super.paint(g);

g.setColor(Color.black);

g.drawRect(0, 0, 100, 100);

}

别踩白块c语言程序编译

只是禅模式的,如果是学习用的,知道一个模式的应该其他也会了,如果是想玩的话下正版吧= =

#include "SDL2/SDL.h"

#include "SDL2/SDL_ttf.h"

#includestring.h

// 使用的头文件

int W; // 窗口宽

int H; // 窗口高

int PH; // 游戏区的高

int i, df = 0; // 定义的变量

char sorry[] = "游戏不适合你的手机", win[9] = "You win!", lose[10] =

"You lose", str[19] = "得分:";

Uint32 began = 0;

float time = 0.0; // 定义的计时变量

bool quit = false; // 退出标志

float X = 0, Y = 0; // 用于获取触控位置的坐标

SDL_Event event;

// 定义一个事件

SDL_Window *w = NULL; // 创建一个窗口指针

SDL_Renderer *ren = NULL; // 创建一个渲染器指针

SDL_Surface *sur = NULL; // 表面

SDL_Surface *sur1 = NULL; // 得分表面

SDL_Surface *text = NULL; // 标题文本区表面

SDL_Texture *tex = NULL; // 画刷

SDL_Texture *tex1 = NULL; // 画刷

SDL_Texture *tex2 = NULL; // 画刷

TTF_Font *font = NULL; // 定义一个字体

SDL_Color color, fontcolor; // 定义字体颜色

SDL_Rect rect[4]; // 屏幕出现的四个黑块

SDL_Rect title; // 标题区

SDL_Rect pp, over;

void change(); // 使方块动起来

void init(); // 启动sdl及相关

void draw(); // 画图

void start(); // 初始化相关数据

void end(); // 游戏结尾

int main(int argc, char **argv)

{ // 主函数

init();

start();

began = SDL_GetTicks(); // 得到开始时间

while (quit == false)

{

draw(); // 画图

while (SDL_PollEvent(event))

{

switch (event.type)

{

case SDL_FINGERDOWN:

X = event.tfinger.x * W;

Y = event.tfinger.y * H;

// 获取x,y的坐标

if (Y rect[0].y)

if ((X rect[0].x) (X (W / 4 + rect[0].x))) // 判断坐标

{

change();

df = df + 1;

}

else // 如果触屏位置不对

{

quit = true;

if (df 3)

sur1 = TTF_RenderUTF8_Blended(font, sorry, color);

else

sur1 = TTF_RenderUTF8_Blended(font, lose, color);

}

break;

case SDL_FINGERUP:

break;

default:;

}

if (df 100) // 如果在30秒内得分超过100

{

quit = true;

sur1 = TTF_RenderUTF8_Blended(font, win, color);

}

}

time = 30 - ((SDL_GetTicks() - began) / 1000); // 计算剩余时间

if (time == 0.0) // 当时间结束

{

quit = true;

sprintf(str, "时间到,得分:%d", df);

sur1 = TTF_RenderUTF8_Blended(font, str, color);

}

}

tex1 = SDL_CreateTextureFromSurface(ren, sur1); // 把表面转换成画刷

SDL_RenderCopy(ren, tex1, NULL, over);

SDL_RenderPresent(ren);

SDL_Delay(3000); // 暂停3秒

end();

return 0;

}

void change()

{

for (int i = 0; i 3; i++)

rect[i].x = rect[i + 1].x;

rect[3].x = (random() % 4) * W / 4; // 最上层产生随机的黑块

}

void init()

{

SDL_Init(SDL_INIT_EVERYTHING);

w = SDL_CreateWindow("别踩白块儿", 0, 0, W, H, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS); // 配置窗口参数并创建

//

//

ren = SDL_CreateRenderer(w, -1, SDL_RENDERER_PRESENTVSYNC); // 为创建的窗口配置渲染器

TTF_Init(); // 启动font

font = TTF_OpenFont("/system/fonts/DroidSansFallback.ttf", 60); // 打开系统自带字体并设置大小为60

}

void draw()

{

sur = SDL_CreateRGBSurface(0, W, H, 32, 0, 0, 0, 0); // 先把表面刷白

SDL_FillRect(sur, NULL, 0xffffff);

for (int i = 0; i 4; i++)

SDL_FillRect(sur, rect[i], 0x00000); // 再把黑块逐个贴上表面

tex = SDL_CreateTextureFromSurface(ren, sur); // 把表面转换成画刷*/

sprintf(str, "得分:%d", df);

sur1 = TTF_RenderUTF8_Blended(font, str, color);

tex1 = SDL_CreateTextureFromSurface(ren, sur1); // 把表面转换成画刷

sprintf(str, "时间:%.2f\"", time);

text = TTF_RenderUTF8_Blended(font, str, fontcolor);

tex2 = SDL_CreateTextureFromSurface(ren, text); // 把表面转换成画刷

SDL_RenderCopy(ren, tex, NULL, NULL);

SDL_RenderCopy(ren, tex2, NULL, title);

SDL_RenderCopy(ren, tex1, NULL, pp);

SDL_RenderPresent(ren);

SDL_FreeSurface(sur);

SDL_DestroyTexture(tex);

SDL_FreeSurface(sur1);

SDL_FreeSurface(text);

SDL_DestroyTexture(tex1);

SDL_DestroyTexture(tex2);

}

void start()

{

SDL_GetWindowSize(w, W, H); // 得到屏幕分辨率

PH = H * 7 / 8;

color =

{

255, 215, 0};

fontcolor =

{

0, 0, 0}; // 字体颜色赋值

float a = PH * 3 / 4 + H / 8;

float wight = W / 4;

float hight = PH / 4;

rect[0].x = 0;

rect[0].y = a;

rect[1].x = wight;

rect[1].y = a - hight;

rect[2].x = wight * 2;

rect[2].y = a - 2 * hight;

rect[3].x = 3 * wight;

rect[3].y = a - 3 * hight;

for (int i = 0; i 4; i++)

{ // 为黑块的高和宽赋值

rect[i].h = hight;

rect[i].w = wight;

}

title =

{

1.10, 0, W / 2, W / 8};

pp =

{

W / 2, 0, W / 2, W / 8};

over =

{

0, H / 4, W, H / 4};

}

void end()

{

TTF_CloseFont(font);

TTF_Quit();

求编写一个超级简单的Java的程序源代码

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class ConstructFrame extends JFrame

{

private static final long serialVersionUID = 1L;

String value1="",result,value2="";

int flag=0,fix=0,sum=1;

Boolean happy;

JTextField text=new JTextField(30);

int flagsum=0;

Container c=getContentPane();

JButton buttonx;

ConstructFrame()

{ super("计算器");

c.setLayout(null);

c.setBackground(Color.blue);

this.setSize(400, 400);

c.add(text);

text.setHorizontalAlignment(JTextField.RIGHT);

final JButton buttonx=new JButton("BackSpace");

c.add(buttonx);

buttonx.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

int count=0;

String temp;

if(flag==0)

{

count=value1.length();

if(count!=1)

temp=value1.substring(0, count-1);

else

temp="0";

value1=temp;

}

else

{

count=value2.length();

if(count!=1)

temp=value2.substring(0, count-1);

else

temp="0";

value2=temp;

}

text.setText(temp);

}

});

final JButton buttony=new JButton("CE");

c.add(buttony);

buttony.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

value1="";

value2="";

flag=0;

text.setText("0");

}

});

final JButton button1=new JButton("1");

c.add(button1);

button1.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+1;

temp=value1;

}

else

{

value2=value2+1;

temp=value2;

}

text.setText(temp);

}

});

final JButton button2=new JButton(" 2 ");

c.add(button2);

button2.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+2;

temp=value1;

}

else

{

value2=value2+2;

temp=value2;

}

text.setText(temp);

}

});

final JButton button3=new JButton("3");

c.add(button3);

button3.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+3;

temp=value1;

}

else

{

value2=value2+3;

temp=value2;

}

text.setText(temp);

}

});

final JButton button4=new JButton("4");

c.add(button4);

button4.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+4;

temp=value1;

}

else

{

value2=value2+4;

temp=value2;

}

text.setText(temp);

}

});

final JButton button5=new JButton("5");

c.add(button5);

button5.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+5;

temp=value1;

}

else

{

value2=value2+5;

temp=value2;

}

text.setText(temp);

}

});

final JButton button6=new JButton("6");

c.add(button6);

button6.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+6;

temp=value1;

}

else

{

value2=value2+6;

temp=value2;

}

text.setText(temp);

}

});

final JButton button7=new JButton("7");

c.add(button7);

button7.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+7;

temp=value1;

}

else

{

value2=value2+7;

temp=value2;

}

text.setText(temp);

}

});

final JButton button8=new JButton("8");

c.add(button8);

button8.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+8;

temp=value1;

}

else

{

value2=value2+8;

temp=value2;

}

text.setText(temp);

}

});

final JButton button9=new JButton("9");

c.add(button9);

button9.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+9;

temp=value1;

}

else

{

value2=value2+9;

temp=value2;

}

text.setText(temp);

}

});

final JButton button0=new JButton("0");

c.add(button0);

button0.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+0;

temp=value1;

}

else

{

value2=value2+0;

temp=value2;

}

text.setText(temp);

}

});

final JButton buttonadd=new JButton(" + ");

c.add(buttonadd);

buttonadd.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=1;

flagsum=0;

}

});

final JButton buttonsubtract=new JButton(" - ");

c.add(buttonsubtract);

buttonsubtract.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=2;

flagsum=0;

}

});

final JButton buttoncheng=new JButton(" * ");

c.add(buttoncheng);

buttoncheng.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=3;

flagsum=0;

}

});

final JButton buttonchu=new JButton(" / ");

c.add(buttonchu);

buttonchu.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

flagsum=0;

fix=4;

}

});

final JButton buttonequal=new JButton(" = ");

c.add(buttonequal);

buttonequal.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

double temp1,temp2;

double temp=0;

flagsum=0;

temp1=Double.parseDouble(value1);

temp2=Double.parseDouble(value2);

flag=0;

switch(fix)

{

case 1: temp=temp1+temp2;break;

case 2: temp=temp1-temp2;break;

case 3: temp=temp1*temp2;break;

case 4: temp=temp1/temp2;break;

}

result=Double.valueOf(temp).toString();

value1=result;

value2="";

flag=1;

text.setText(result);

}

});

final JButton buttonpoint=new JButton(".");

c.add(buttonpoint);

buttonpoint.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{ if(flagsum==0)

{

String temp;

if(flag==0 )

{

value1=value1+".";

temp=value1;

}

else

{

value2=value2+".";

temp=value2;

}

flagsum=1;

text.setText(temp);

}

}

});

JButton buttonz=new JButton("Start");

c.add(buttonz);

buttonz.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{ if(sum%2==1)

{

happy=true;

text.setText("0.");

flag=0;

}

else

{

happy=false;

value1="";

value2="";

text.setText("");

}

text.setEnabled(happy);

button1.setEnabled(happy);

button2.setEnabled(happy);

button3.setEnabled(happy);

button4.setEnabled(happy);

button5.setEnabled(happy);

button6.setEnabled(happy);

button7.setEnabled(happy);

button8.setEnabled(happy);

button9.setEnabled(happy);

button0.setEnabled(happy);

buttonx.setEnabled(happy);

buttony.setEnabled(happy);

buttonadd.setEnabled(happy);

buttonsubtract.setEnabled(happy);

buttonpoint.setEnabled(happy);

buttonequal.setEnabled(happy);

buttoncheng.setEnabled(happy);

buttonchu.setEnabled(happy);

sum++;

}

});

button1.setEnabled(false);

button2.setEnabled(false);

button3.setEnabled(false);

button4.setEnabled(false);

button5.setEnabled(false);

button6.setEnabled(false);

button7.setEnabled(false);

button8.setEnabled(false);

button9.setEnabled(false);

button0.setEnabled(false);

buttonx.setEnabled(false);

buttony.setEnabled(false);

buttonadd.setEnabled(false);

buttonsubtract.setEnabled(false);

buttonpoint.setEnabled(false);

buttonequal.setEnabled(false);

buttoncheng.setEnabled(false);

buttonchu.setEnabled(false);

text.setEnabled(false);

text.setBounds(20, 20, 200, 40);

buttonx.setBounds(20, 60,100, 40);

buttony.setBounds(140, 60,100, 40);

buttonz.setBounds(260, 60,80, 40);

button1.setBounds(20, 120,60, 40);

button2.setBounds(100, 120,60, 40);

button3.setBounds(180, 120,60, 40);

buttonadd.setBounds(260, 120,60, 40);

button4.setBounds(20, 180,60, 40);

button5.setBounds(100, 180,60, 40);

button6.setBounds(180, 180,60, 40);

buttonsubtract.setBounds(260, 180,60, 40);

button7.setBounds(20, 240,60, 40);

button8.setBounds(100, 240,60, 40);

button9.setBounds(180, 240,60, 40);

buttoncheng.setBounds(260,240,60,40);

button0.setBounds(20, 300,60, 40);

buttonpoint.setBounds(100, 300, 60, 40);

buttonequal.setBounds(180,300,60, 40);

buttonchu.setBounds(260, 300,60, 40);

setVisible(true);

}

class MYMouseEvent extends MouseAdapter

{

public void mousePressed(MouseEvent e)

{

value1=e.toString();

text.setText(value1);

}

}

}

class Calutator

{

public static void main(String[] args)

{

new ConstructFrame();

}

}

你自己慢慢的看吧!

【急】有没有朋友用java写过别踩白块,急求源码!

package 别踩白块;

import java.awt.GridLayout;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import javax.swing.JFrame;

public class Main extends JFrame implements MouseListener {

Block[] block=new Block[9];

Block1 block1=new Block1();

public Main(){

setTitle("别踩白块");

setBounds(200,300,200,300);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new GridLayout(3,3,5,5));

addblock();

bk();

this.setVisible(true);

}

public void addblock(){

for(int i=0;i9;i++)

{

block[i]=new Block();

add(block[i]);

}

}

public void bk(){

block1.setbk1(block[(int)(Math.random()*2)]);

block1.setbk1(block[(int)(Math.random()*2+4)]);

block1.setbk1(block[(int)(Math.random()*2+6)]);

}

public void over(){

block[3].setText("g");

block[4].setText("g");

block[5].setText("!");

}

public static void main(String[] args) {

// TODO Auto-generated method stub

new Main();

}

@Override

public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mousePressed(MouseEvent e) {

// TODO Auto-generated method stub

if(e.getSource().equals(""));

over();

}

@Override

public void mouseReleased(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseEntered(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseExited(MouseEvent e) {

// TODO Auto-generated method stub

}

}


本文名称:别踩白块java程序代码 别踩白块编程
网站地址:http://kswsj.cn/article/doocdoc.html

其他资讯