求助:一个java小游戏编程实例,主界面做好了,但是游戏中间按钮不知道怎么写。

导入javax . swing . *;

导入Java . awt . *;

导入Java . awt . event . *;

公共类Game1扩展javax.swing.JFrame {

公共游戏1() {

init components();

}

私有void initComponents() {

jbutton 1 = new javax . swing . jbutton();

jbutton 2 = new javax . swing . jbutton();

jbutton 3 = new javax . swing . jbutton();

jbutton 4 = new javax . swing . jbutton();

jbutton 5 = new javax . swing . jbutton();

jbutton 6 = new javax . swing . jbutton();

jbutton 7 = new javax . swing . jbutton();

setDefaultCloseOperation(javax . swing . window constants . exit _ ON _ CLOSE);

jbutton 1 . set icon(new javax . swing . image icon(" c:\ \ users \ \ administrator \ \ desktop \ \ game . jpg "));

jbutton 1 . settext(" jbutton 1 ");

jbutton 1 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 1 action performed(evt);

}

});

jbutton 2 . set icon(new javax . swing . image icon(" c:\ \ users \ \ administrator \ \ desktop \ \ game . jpg "));

jbutton 2 . settext(" jbutton 2 ");

jbutton 2 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 2 action performed(evt);

}

});

jbutton 3 . set icon(new javax . swing . image icon(" c:\ \ users \ \ administrator \ \ desktop \ \ game . jpg "));

jbutton 3 . settext(" jbutton 3 ");

jbutton 3 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 3 action performed(evt);

}

});

jbutton 4 . set icon(new javax . swing . image icon(" c:\ \ users \ \ administrator \ \ desktop \ 2 . jpg "));

jbutton 4 . settext(" jbutton 4 ");

jbutton 4 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 4 action performed(evt);

}

});

jbutton 5 . set icon(new javax . swing . image icon(" C:\ \ Users \ \ Administrator \ \ Desktop \ Game 1 . jpg "));// NOI18N

jbutton 5 . settext(" jbutton 5 ");

jbutton 5 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 5 action performed(evt);

}

});

jbutton 6 . set icon(new javax . swing . image icon(" C:\ \ Users \ \ Administrator \ \ Desktop \ Game 1 . jpg "));// NOI18N

jbutton 6 . settext(" jbutton 6 ");

jbutton 6 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 6 action performed(evt);

}

});

jbutton 7 . set icon(new javax . swing . image icon(" C:\ \ Users \ \ Administrator \ \ Desktop \ Game 1 . jpg "));// NOI18N

jbutton 7 . settext(" ");

jbutton 7 . addactionlistener(new Java . awt . event . action listener(){

public void action performed(Java . awt . event . action event evt){

jbutton 7 action performed(evt);

}

});

javax . swing . group layout layout = new javax . swing . group layout(getContentPane());

getContentPane()。setLayout(布局);

layout.setHorizontalGroup(

layout . createparallelgroup(javax . swing . group layout . alignment . leading)

。add group(layout . create sequential group()

。addGap(132,132,132)

。add group(layout . createparallelgroup(javax . swing . group layout . alignment . trailing,false)

。addComponent(jButton1,javax . swing . group layout . alignment . leading,0,0,Short。最大值)

。addComponent(jButton2,javax . swing . group layout . alignment . leading,0,0,Short。最大值)

。addComponent(jButton3,javax . swing . group layout . alignment . leading,0,0,Short。最大值)

。addComponent(jButton4,javax . swing . group layout . alignment . leading,0,0,Short。最大值)

。addComponent(jButton5,javax . swing . group layout . alignment . leading,0,0,Short。最大值)

。addComponent(jButton6,0,0,Short。最大值)

。addComponent(jButton7,javax . swing . group layout . preferred _ SIZE,69,Short。最大值))

。addContainerGap(199,短。最大值))

);

layout.setVerticalGroup(

layout . createparallelgroup(javax . swing . group layout . alignment . leading)

。add group(layout . create sequential group()

。addGap(101,101,101)

。添加组件(jButton7)

。addGap(29,29,29)

。添加组件(jButton6)

。addGap(30,30,30)

。添加组件(jButton5)

。addPreferredGap(javax . swing . layout style . component placement . related,javax . swing . group layout . default _ SIZE,Short。最大值)

。添加组件(jButton4)

。addGap(18,18,18)

。addComponent(jButton3)

。addGap(18,18,18)

。addComponent(jButton2)

。addGap(18,18,18)

。addComponent(jButton1))

);

pack();

}//& lt;/editor-fold & gt;

private void jbutton 1 action performed(Java . awt . event . action event evt){

如果(a==0)

{

如果(a!=b)

{

如果(b==2)

{

jbutton 2 . seticon(f 1);

jbutton 1 . seticon(F3);

a = 2;

b = 0;

}

其他

{

如果(c==2)

{

jbutton 3 . seticon(f 1);

jbutton 1 . seticon(F3);

c = 0;

a = 2;

}

}

}

}

}

private void jbutton 2 action performed(Java . awt . event . action event evt){

如果(b==0)

{

如果(b!=c)

{

如果(c==2)

{

jbutton 3 . seticon(f 1);

jbutton 2 . seticon(F3);

b = 2;

c = 0;

}

其他

{

如果(d==2)

{

jbutton 4 . seticon(f 1);

jbutton 2 . seticon(F3);

d = 0;

b = 2;

}

}

}

}

if(b==1)

{

如果(a==2)

{

jbutton 1 . seticon(F2);

jbutton 2 . seticon(F3);

b = 2;

a = 1;

}

}

}

private void jbutton 3 action performed(Java . awt . event . action event evt){

如果(c==0)

{

如果(c!=d)

{

如果(d==2)

{

jbutton 4 . seticon(f 1);

jbutton 3 . seticon(F3);

c = 2;

d = 0;

}

其他

{

如果(e==2)

{

jbutton 5 . seticon(f 1);

jbutton 3 . seticon(F3);

e = 0;

c = 2;

}

}

}

}

if(c==1)

{

if(b = = 0 & amp;& ampa==2)

{

jbutton 1 . seticon(F2);

jbutton 3 . seticon(F3);

c = 2;

a = 1;

}

如果(b==2)

{

jbutton 2 . seticon(F2);

jbutton 3 . seticon(F3);

c = 2;

b = 1;

}

}

}

private void jbutton 4 action performed(Java . awt . event . action event evt){

如果(d==0)

{

如果(d!=e)

{

如果(e==2)

{

jbutton 5 . seticon(f 1);

jbutton 4 . seticon(F3);

d = 2;

e = 0;

}

其他

{

如果(f==2)

{

jbutton 6 . seticon(f 1);

jbutton 4 . seticon(F3);

f = 0;

d = 2;

}

}

}

}

如果(d==1)

{

if(c = = 0 & amp;& ampb==2)

{

jbutton 2 . seticon(F2);

jbutton 4 . seticon(F3);

d = 2;

b = 1;

}

如果(c==2)

{

jbutton 3 . seticon(F2);

jbutton 4 . seticon(F3);

d = 2;

c = 1;

}

}

}

private void jbutton 5 action performed(Java . awt . event . action event evt){

如果(e==0)

{

如果(e!=f)

{

如果(f==2)

{

jbutton 6 . seticon(f 1);

jbutton 5 . seticon(F3);

e = 2;

f = 0;

}

其他

{

如果(g==2)

{

jbutton 7 . seticon(f 1);

jbutton 5 . seticon(F3);

g = 0;

e = 2;

}

}

}

}

如果(e==1)

{

if(d = = 0 & amp;& ampc==2)

{

jbutton 3 . seticon(F2);

jbutton 5 . seticon(F3);

e = 2;

c = 1;

}

如果(d==2)

{

jbutton 4 . seticon(F2);

jbutton 5 . seticon(F3);

e = 2;

d = 1;

}

}}

private void jbutton 6 action performed(Java . awt . event . action event evt){

if(f = = 0 & amp;& ampg==2)

{

jbutton 7 . seticon(f 1);

jbutton 6 . seticon(F3);

f = 2;

g = 0;

}

if(f = = 1 & amp;& ampe==2)

{

jbutton 5 . seticon(F2);

jbutton 6 . seticon(F3);

f = 2;

e = 1;

}

if(f = = 1 & amp;& ampe = = 0 & amp& ampd==2)

{

jbutton 4 . seticon(F2);

jbutton 6 . seticon(F3);

d = 1;

f = 2;

}

}

private void jbutton 7 action performed(Java . awt . event . action event evt){

if(g = = 1 & amp;& ampf==2)

{

jbutton 6 . seticon(F2);

jbutton 7 . seticon(F3);

g = 2;

f = 1;

}

if(g = = 1 & amp;& ampf = = 0 & amp& ampe==2)

{

jbutton 5 . seticon(F2);

jbutton 7 . seticon(F3);

g = 2;

e = 1;

}

}

公共静态void main(String args[]) {

Java . awt . event queue . invoke later(new Runnable(){

公共无效运行(){

新游戏1()。set visible(true);

}

});

}

//变量声明-不要修改

private javax . swing . jbutton jbutton 1;

private javax . swing . jbutton jbutton 2;

private javax . swing . jbutton jbutton 3;

private javax . swing . jbutton jbutton 4;

private javax . swing . jbutton jbutton 5;

private javax . swing . jbutton jbutton 6;

private javax . swing . jbutton jbutton 7;

//变量声明结束

int a = 0;int b = 0;int c = 0;int d = 2;int e = 1;int f = 1;int g = 1;

string s = " c:\ \ users \ \ administrator \ \ desktop \ \ game . jpg ";

string s 1 = " C:\ \ Users \ \ Administrator \ \ Desktop \ \ Game 1 . jpg ";

字符串S2 = "C: \ \用户\ \管理员\ \桌面\ \ 2 . jpg ";

image icon f 1 = new image icon(" c:\ \ users \ \ administrator \ \ desktop \ \ game . jpg ");

image icon F2 = new image icon(" C:\ \ Users \ \ Administrator \ \ Desktop \ \ Game 1 . jpg ");

image icon F3 = new image icon(" c:\ \ users \ \ administrator \ \ desktop \ \ 2 . jpg ");

}//我对“点击一个按钮每隔一个按钮移动一次,相邻的两个按钮必须有箭头相向”的理解是,两个箭头相向的按钮只有后面有空格才能移动。不知道对不对,也不会把按钮做成圆形。你可以使用你的界面。如果我没理解错的话,里面的方法和思路应该可以解决运动问题。此外,我将向下按钮模式保存为。

游戏。jpg向上我为游戏存1 . jpg;我为游戏2.jpg保留的空缺按钮。