「java演示有趣」java实现的有趣的应用

博主:adminadmin 2022-11-27 00:52:06 75

今天给各位分享java演示有趣的知识,其中也会对java实现的有趣的应用进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

用Java可以做哪些有趣的事情?

像Industrial Light and Magic这样的公司,就依赖Java来满足各种编程需求。事实上,你经常可以在ILM上发现几乎任何有开发需要的工作。在ILM工作有意思的地方在于,你可以把应用程序一起放到在大屏幕上查看结果。目前,ILM使用Java和Python来处理诸如测序动画场景等任务。

求一个简单又有趣的JAVA小游戏代码

具体如下:

连连看的小源码

package Lianliankan;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组

JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮

JLabel fractionLable=new JLabel("0"); //分数标签

JButton firstButton,secondButton; //

分别记录两次62616964757a686964616fe59b9ee7ad9431333335326239被选中的按钮

int grid[][] = new int[8][7];//储存游戏按钮位置

static boolean pressInformation=false; //判断是否有按钮被选中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标

int i,j,k,n;//消除方法控制

代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。

对于字符和Unicode数据的位模式的定义,此模式代表特定字母、数字或符号(例如 0x20 代表一个空格,而 0x74 代表字符“t”)。一些数据类型每个字符使用一个字节;每个字节可以具有 256 个不同的位模式中的一个模式。

在计算机中,字符由不同的位模式(ON 或 OFF)表示。每个字节有 8 位,这 8 位可以有 256 种不同的 ON 和 OFF 组合模式。对于使用 1 个字节存储每个字符的程序,通过给每个位模式指派字符可表示最多 256 个不同的字符。2 个字节有 16 位,这 16 位可以有 65,536 种唯一的 ON 和 OFF 组合模式。使用 2 个字节表示每个字符的程序可表示最多 65,536 个字符。

单字节代码页是字符定义,这些字符映射到每个字节可能有的 256 种位模式中的每一种。代码页定义大小写字符、数字、符号以及 !、@、#、% 等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。

虽然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间交换数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。

如果某个数据库为来自许多不同国家的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。

有没有关于JAVA的一些简单又有趣的程序

import javax.swing.JPanel;

import javax.swing.JFrame;

import javax.swing.JButton;

import java.awt.Point;

import java.awt.Rectangle;

import javax.swing.ImageIcon;

import java.awt.Color;

import javax.swing.JLabel;

import java.awt.Font;

import java.net.URL;

import java.net.URLClassLoader;

import java.util.ArrayList;

import java.util.Date;

public class Game extends JFrame {

/**

* This method initializes jButton1

*

* @return javax.swing.JButton

*/

private JButton getJButton1() {

if (jButton1 == null) {

jButton1 = new JButton();

jButton1.setBounds(new Rectangle(478, 361, 164, 51));

jButton1.setText("重新开始");

jButton1.setVisible(false);

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

jButton1.setVisible(false);

jLabel.setVisible(false);

try {

Thread.sleep(1000);

} catch (InterruptedException e1) {

// TODO 自动生成 catch 块

e1.printStackTrace();

}

reset();

}

});

}

return jButton1;

}

public static void main(String[] args) {

Game game = new Game();

game.start();

game.reset();

game.gogo();

}

public void reset() {

kup = false;

kdown = false;

kleft = false;

kright = false;

int chushihua = 0;

while (chushihua zidanshu) {

((JButton) buttonal.get(chushihua)).setBounds(new Rectangle(-50,

-50, 10, 10));

chushihua++;

}

gamexunhuan = true;

jButton.setIcon(new ImageIcon(fileLoc));

jButton.setLocation(320, 320);

p = jButton.getLocation();

x=p.getX();

y=p.getY();

firsttime=new Date().getTime();

}

public void start() {

int chushihua = 0;

while (chushihua zidanshu) {

JButton jb = new JButton();

jb.setBounds(new Rectangle(-50, -50, 10, 10));

jb.setEnabled(false);

Threads ths = new Threads(jb);

Thread th = new Thread(ths);

buttonal.add(jb);

threadal.add(th);

chushihua++;

}

Game.Move move = new Move();

Thread tm = new Thread(move);

tm.start();

}

public void gogo() {

int chushihua = 0;

while (chushihua zidanshu) {

((Thread) threadal.get(chushihua)).start();

chushihua++;

try {

Thread.sleep(100);

} catch (InterruptedException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

}

}

}

// private static Game game;

private long firsttime;

private long lasttime;

private static final long serialVersionUID = 1L;

private JPanel jPanel = null;

private JButton jButton = null;

private boolean kup ;

private boolean kdown ;

private boolean kleft ;

private boolean kright ;

// 定义玩家的行走步伐,数值越大,移动速度越快 private int step = 3;

Point p; // @jve:decl-index=0:

double x = 0.0;

double y = 0.0;

// 定义了子弹的个数 int zidanshu = 70;

// 定义子弹初始值,这个是不变的

// int chushihua = 0;

// 定义控制子弹行走的循环false就不走了

private boolean gamexunhuan = true;

private JLabel jLabel = null;

private JButton jButton1 = null;

private ArrayList buttonal = new ArrayList();

private ArrayList threadal = new ArrayList();

URLClassLoader urlLoader = (URLClassLoader)this.getClass().getClassLoader();

URL fileLoc = urlLoader.findResource("MyGameIcons/gwl1.gif"); // @jve:decl-index=0:

URL fileLoc1 = urlLoader.findResource("MyGameIcons/gwls1.gif");

/**

* This is the default constructor

*/

public Game() {

super();

initialize();

}

/**

* This method initializes this

*

* @return void

*/

private void initialize() {

this.setSize(700, 700);

this.addWindowListener(new java.awt.event.WindowAdapter() {

public void windowClosing(java.awt.event.WindowEvent e) {

System.exit(1);

}

});

this.setResizable(false);

this.setContentPane(getJPanel());

this.setTitle("范传奇的小游戏!(模拟撑过30秒的小DEMO)");

this.setVisible(true);

}

/**

* This method initializes jPanel

*

* @return javax.swing.JPanel

*/

private JPanel getJPanel() {

if (jPanel == null) {

jLabel = new JLabel();

jLabel.setBounds(new Rectangle(42, -33, 595, 308));

jLabel.setFont(new Font("Dialog", Font.BOLD, 24));

jLabel.setForeground(new Color(250, 2, 2));

jLabel.setEnabled(true);

jLabel.setVisible(false);

jPanel = new JPanel();

jPanel.setLayout(null);

jPanel.add(getJButton(), null);

jPanel.setForeground(new Color(1, 1, 1));

jPanel.setBackground(new Color(1, 1, 1));

jPanel.setVisible(true);

jPanel.add(jLabel, null);

jPanel.add(getJButton1(), null);

}

return jPanel;

}

/**

* This method initializes jButton

*

* @return javax.swing.JButton

*/

class Move implements Runnable {

public void run() {

while(true){

while (gamexunhuan) {

p = jButton.getLocation();

if (kup) {

if (kleft) {

x = p.getX();

y = p.getY();

if (x 0 y 0) {

jButton.setLocation((int) x - step, (int) y

- step);

}

} else if (kright) {

x = p.getX();

y = p.getY();

if (x + 40 700 y 0) {

jButton.setLocation((int) x + step, (int) y

- step);

}

} else {

x = p.getX();

y = p.getY();

if (y 0) {

jButton.setLocation((int) x, (int) y - step);

}

}

}

if (kdown) {

if (kleft) {

x = p.getX();

y = p.getY();

if (y + 60 700 x 0) {

jButton.setLocation((int) x - step, (int) y

+ step);

}

} else if (kright) {

x = p.getX();

y = p.getY();

if (x + 40 700 y + 60 700) {

jButton.setLocation((int) x + step, (int) y

+ step);

}

} else {

x = p.getX();

y = p.getY();

if (y + 60 700) {

jButton.setLocation((int) x, (int) y + step);

}

}

}

if (kleft) {

if (kup) {

x = p.getX();

y = p.getY();

if (x 0 y 0) {

jButton.setLocation((int) x - step, (int) y

- step);

}

} else if (kdown) {

x = p.getX();

y = p.getY();

if (y + 60 700 x 0) {

jButton.setLocation((int) x - step, (int) y

+ step);

}

} else {

x = p.getX();

y = p.getY();

if (x 0) {

jButton.setLocation((int) x - step, (int) y);

}

}

}

if (kright) {

if (kup) {

x = p.getX();

y = p.getY();

if (x + 40 700 y 0) {

jButton.setLocation((int) x + step, (int) y

- step);

}

} else if (kdown) {

x = p.getX();

y = p.getY();

if (x + 40 700 y + 60 700) {

jButton.setLocation((int) x + step, (int) y

+ step);

}

} else {

x = p.getX();

y = p.getY();

if (x + 40 700) {

jButton.setLocation((int) x + step, (int) y);

}

}

}

try {

Thread.sleep(10);

} catch (InterruptedException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

}

}

try {

Thread.sleep(50);

} catch (InterruptedException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

}

}

}

}

private JButton getJButton() {

if (jButton == null) {

jButton = new JButton();

jButton.setBounds(new Rectangle(320, 320, 30, 30));

jButton.setBackground(new Color(1, 1, 1));

p = jButton.getLocation();

x = p.getX();

y = p.getY();

jButton.setIcon(new ImageIcon(fileLoc));

jButton.addKeyListener(new java.awt.event.KeyAdapter() {

public void keyReleased(java.awt.event.KeyEvent e) {

if(e.getKeyCode()==10){

if(!gamexunhuan){

jButton1.setVisible(false);

jLabel.setVisible(false);

reset();

}

}

if (e.getKeyCode() == 37) {

kleft = false;

}

if (e.getKeyCode() == 38) {

kup = false;

}

if (e.getKeyCode() == 39) {

kright = false;

}

if (e.getKeyCode() == 40) {

kdown = false;

}

}

public void keyPressed(java.awt.event.KeyEvent e) {

if (e.getKeyCode() == 37) {

kleft = true;

}

if (e.getKeyCode() == 38) {

kup = true;

}

// 触发按右键

if (e.getKeyCode() == 39) {

kright = true;

}

if (e.getKeyCode() == 40) {

kdown = true;

}

}

});

}

return jButton;

}

class Threads implements Runnable {

public Threads(JButton jjb) {

jb = jjb;

}

JButton jb = null;

private boolean first = true;

public void run() {

while (gamexunhuan) {

go();

}

}

public void go() {

int zzx = 0;

int zzy = 0;

int zx = 0;

int zy = 0;

while (true) {

if(gamexunhuan){

int fangxiang = (int) (Math.random() * 4 + 1);

// 四个if随即从四个边发射子弹

if (fangxiang == 1) {

zx = 0;

zy = (int) (Math.random() * 701);

}

if (fangxiang == 2) {

zx = (int) (Math.random() * 701);

zy = 0;

}

if (fangxiang == 3) {

zx = 700;

zy = (int) (Math.random() * 701);

}

if (fangxiang == 4) {

zx = (int) (Math.random() * 701);

zy = 700;

}

// 初始化子弹,有了就不在加了

if (first) {

jPanel.add(jb, null);

first = false;

}

jb.setBounds(new Rectangle(zx, zy, 10, 10));

// 定义子弹与物体之间的步长

zzx = (int) (((x + 15) - zx) / 30);

zzy = (int) (((y + 15) - zy) / 30);

}

while (gamexunhuan) {

try {

zx += zzx;

zy += zzy;

jb.setLocation(zx, zy);

if (zx + 5 x zx + 5 x + 30 zy + 5 y

zy + 5 y + 30) {

jButton.setIcon(new ImageIcon(fileLoc1));

gamexunhuan = false;

first = true;

jButton1.setVisible(true);

jLabel.setVisible(true);

lasttime = new Date().getTime();

Date gametime = new Date(lasttime-firsttime);

int min =0;

int sec =0;

min = gametime.getMinutes();

sec = gametime.getSeconds();

String endtime = "";

if(min!=0){

endtime=min + "分 " + sec + "秒";

}else{

endtime=sec + "秒";

}

jLabel.setText(" GAME OVER!!! \n用时:" + endtime);

break;

}

// 超出边线停止循环

if (zx 700 | zy 700 | zx 0 | zy 0) {

break;

}

Thread.sleep(60);

} catch (InterruptedException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

}

}

try {

Thread.sleep(50);

} catch (InterruptedException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

}

}

}

}

} // @jve:decl-index=0:visual-constraint="10,10"

这是一个以前写过的“是男人就撑过30秒的小游戏源码”

如果想要执行程序,麻烦留个邮箱。

用Java可以做哪些有趣的事情

可以写个公共号,用别人身份证注册,用黑卡绑定,然后再国外使用假信息搞个vps,然后java就派上用场了,写个爬虫自动爬番号,爬引擎,爬种子,爬图片,然后每天晚上11点左右(为什么是这个时间,大家都懂的。)推送给大家,或者直接link到磁力p2p,然后就可以放心大胆的飙车了,再然后请大家赶紧排队刷卡上车。

java演示有趣的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java实现的有趣的应用、java演示有趣的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-27,除非注明,否则均为首码项目网原创文章,转载请注明出处。