网站首页 > 文章中心 > 其它

Java著名代码网名

作者:小编 更新时间:2023-08-16 12:49:33 浏览量:404人看过

求java小游戏源代码

表1. CheckerDrag.java

JAVA代码

连连看java源代码

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

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

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

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

JButton firstButton,secondButton; //分别记录两次被选中的按钮

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

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

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

public void init(){

mainFrame=new JFrame("JKJ连连看");

thisContainer = mainFrame.getContentPane();

thisContainer.setLayout(new BorderLayout());

centerPanel=new JPanel();

southPanel=new JPanel();

northPanel=new JPanel();

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,"North");

diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols◆1][rows◆1]));

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

exitButton=new JButton("退出");

exitButton.addActionListener(this);

resetButton=new JButton("重列");

resetButton.addActionListener(this);

newlyButton=new JButton("再来一局");

newlyButton.addActionListener(this);

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));

northPanel.add(fractionLable);

mainFrame.setVisible(true);

public void randomBuild() {

int randoms,cols,rows;

while(grid[cols][rows]!=0) {

this.grid[cols][rows]=randoms;

public void fraction(){

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())◆100));

public void reload() {

int n=0,cols,rows;

if(this.grid[i][j]!=0) {

save[n]=this.grid[i][j];

n◆◆;

n=n-1;

this.grid=grid;

while(n=0) {

this.grid[cols][rows]=save[n];

n--;

mainFrame.setVisible(false);

init();

if(grid[i◆1][j◆1]==0)

diamondsButton[i][j].setVisible(false);

public void estimateEven(int placeX,int placeY,JButton bz) {

if(pressInformation==false) {

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

pressInformation=true;

else {

x0=x;

y0=y;

fristMsg=secondMsg;

firstButton=secondButton;

if(fristMsg==secondMsg secondButton!=firstButton){

xiao();

public void xiao() { //相同的情况下能不能消去.仔细分析,不一条条注释

if((x0==x (y0==y◆1||y0==y-1)) || ((x0==x◆1||x0==x-1)(y0==y))){ //判断是否相邻

remove();

else{

if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空

if (yj) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边

for (i=y-1;i=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0) {

k=0;

break;

else //K=1说明通过了第一次验证

if (k==1) {

linePassOne();

if (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边

for (i=y◆1;i=j ;i◆◆ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0){

else

if (k==1){

if (y==j ) {

if (x0==x) {

if (x0x) {

for (n=x0;n=x-1;n◆◆ ) {

if (grid[n][j]!=0) {

if(grid[n][j]==0 n==x-1) {

for (n=x0;n=x◆1 ;n-- ) {

if(grid[n][j]==0 n==x◆1) {

if (grid[i][y0]==0) {

if (xi) {

for (j=x-1;j=i ;j-- ) {

if (grid[j][y]!=0) {

rowPassOne();

for (j=x◆1;j=i;j◆◆ ) {

if (x==i) {

if (y0==y) {

if (y0y) {

for (n=y0;n=y-1 ;n◆◆ ) {

if (grid[i][n]!=0) {

if(grid[i][n]==0 n==y-1) {

for (n=y0;n=y◆1 ;n--) {

if(grid[i][n]==0 n==y◆1) {

public void linePassOne(){

if (y0j){ //第一按钮同行空按钮在左边

for (i=y0-1;i=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮

if (grid[x0][i]!=0) {

if (y0j){ //第一按钮同行空按钮在与第二按钮之间

for (i=y0◆1;i=j ;i◆◆){

public void rowPassOne(){

if (x0i) {

for (j=x0-1;j=i ;j-- ) {

if (grid[j][y0]!=0) {

for (j=x0◆1;j=i ;j◆◆ ) {

public void remove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

pressInformation=false;

grid[x0][y0]=0;

grid[x][y]=0;

public void actionPerformed(ActionEvent e) {

if(e.getSource()==newlyButton){

this.grid = grid;

randomBuild();

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols◆1,rows◆1,diamondsButton[cols][rows]);

public static void main(String[] args) {

lianliankan llk = new lianliankan();

llk.randomBuild();

llk.init();

给段最简单的java代码 让我新手看一下

最简单的java代码肯定就是这个了,如下:

public class MyFirstApp

public static void main(String[] args)

System.out.print("Hello world");

java编码规范有哪些?

尽量使用完整的英文描述符,采用适用于相关领域的术语,采用大小写混合使名字可读.

JAVA代码规范:

(1)类名首字母应该大写.字段、方法以及对象(句柄)的首字母应小写.对于所有标识符,其中包含的所有单词都应紧靠在一起,而且大写中间单词的首字母.例如:

ThisIsAClassName

thisIsMethodOrFieldName

hashCode()

toString()

clone()(implement Cloneable)

implement Serializable

一个复杂的开关语句:考虑采用"多形"机制

数量众多的方法涉及到类型差别极大的操作:考虑用几个类来分别实现

许多成员变量在特征上有很大的差别:考虑使用几个类

几个Java小游戏代码

package reduce;

import java.applet.Applet;

import java.applet.AudioClip;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Toolkit;

import javax.sound.sampled.AudioFileFormat;

import javax.sound.sampled.AudioSystem;

import javax.swing.JFrame;

import javax.swing.JPanel;

import java.awt.Rectangle;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JOptionPane;

import javax.swing.JSlider;

import javax.swing.JLabel;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.io.File;

import java.util.Vector;

public class Frame extends JFrame implements Runnable {

JPanel contentPane;

JPanel jPanel1 = new JPanel();

JButton jButton1 = new JButton();

JSlider jSlider1 = new JSlider();

JLabel jLabel1 = new JLabel();

int zhengque = 0, cuowu = 0;

int rush_count = 0; //记录关数

char list[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',

'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',

Vector number = new Vector();

String paiduan = "true";

AudioClip Musci_anjian, Music_shibai, Music_chenggong;

public Frame() {

try {

setDefaultCloseOperation(EXIT_ON_CLOSE);

//-----------------声音文件---------------------

Musci_anjian = Applet.newAudioClip(new File("sounds//anjian.wav")

.toURL());

Music_shibai = Applet.newAudioClip(new File("sounds//shibai.wav")

Music_chenggong = Applet.newAudioClip(new File(

"sounds//chenggong.wav").toURL());

//---------------------------------------

jbInit();

} catch (Exception exception) {

exception.printStackTrace();

/**

* Component initialization.

*

* @throws java.lang.Exception

*/

private void jbInit() throws Exception {

contentPane = (JPanel) getContentPane();

contentPane.setLayout(null);

setTitle("Frame Title");

jPanel1.setBorder(BorderFactory.createEtchedBorder());

jPanel1.setLayout(null);

jButton1.setText("开始");

jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));

jSlider1.setMaximum(100);

jSlider1.setMinimum(1);

jLabel1.setText("速度");

contentPane.add(jPanel1);

contentPane.add(jButton1);

contentPane.add(jSlider1);

contentPane.add(jLabel1);

this.addKeyListener(new MyListener());

jButton1.addKeyListener(new MyListener());

jSlider1.addKeyListener(new MyListener());

jSlider1.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent e) {

rapidity = jSlider1.getValue();

});

public void run() {

number.clear();

zhengque = 0;

cuowu = 0;

paiduan = "true";

while (count = rush[rush_count]) {

Thread t = new Thread(new Tthread());

t.start();

count ◆= 1;

} catch (InterruptedException e) {

e.printStackTrace();

while (true) { // 等待最后一个字符消失

if (number.size() == 0) {

if (zhengque == 0) { // 为了以后相除..如果全部正确或者错误就会出现错误. 所以..

zhengque = 1;

if (cuowu == 0) {

cuowu = 1;

if (paiduan.equals("true")) { // 判断是否是自然结束

JOptionPane.showMessageDialog(null, "恭喜你过关了");

rush_count ◆= 1; // 自动加1关

if (rush_count rush.length) {

jSlider1.setValue(rapidity); // 选择位置

Thread t = new Thread(this);

} else {

JOptionPane.showMessageDialog(null, "牛B...你通关了..");

rush_count = 0;

count = 0;

JOptionPane.showMessageDialog(null, "请再接再励");

public void jButton1_actionPerformed(ActionEvent e) {

count = rush[rush_count] ◆ 1;

paiduan = "flase";

class Tthread implements Runnable {

boolean fo = true;

int Y = 0, X = 0;

JLabel show = new JLabel();

jPanel1.add(show);

String parameter = list[(int) (Math.random() * list.length)] ◆ "";

Bean bean = new Bean();

bean.setParameter(parameter);

bean.setShow(show);

number.add(bean);

show.setText(parameter);

while (fo) {

// ---------------------数字下移--------------------

Thread.sleep(rapidity);

fo = false;

for (int i = number.size() - 1; i = 0; i--) {

Bean bn = ((Bean) number.get(i));

if (parameter.equalsIgnoreCase(bn.getParameter())) {

cuowu ◆= 1;

◆ "个");

number.removeElementAt(i);

Music_shibai.play();

class MyListener extends KeyAdapter {

public void keyPressed(KeyEvent e) {

String uu = e.getKeyChar() ◆ "";

for (int i = 0; i number.size(); i◆◆) {

Bean bean = ((Bean) number.get(i));

if (uu.equalsIgnoreCase(bean.getParameter())) {

zhengque ◆= 1;

bean.getShow().setVisible(false);

Music_chenggong.play();

Musci_anjian.play();

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Frame frame = new Frame();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = frame.getSize();

if (frameSize.height screenSize.height) {

frameSize.height = screenSize.height;

if (frameSize.width screenSize.width) {

frameSize.width = screenSize.width;

frame.setVisible(true);

private Frame adaptee;

this.adaptee = adaptee;

class Frame1_jButton1_actionAdapter implements ActionListener {

Frame1_jButton1_actionAdapter(Frame adaptee) {

adaptee.jButton1_actionPerformed(e);

class Bean {

String parameter = null;

JLabel show = null;

public JLabel getShow() {

return show;

public void setShow(JLabel show) {

this.show = show;

public String getParameter() {

return parameter;

public void setParameter(String parameter) {

this.parameter = parameter;

我只有一个打字母小游戏

java设计微信账号类,微信号,手机号,昵称怎么写

①.、首先打开<>这款软件.

以上就是土嘎嘎小编为大家整理的Java著名代码网名相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章