📄 movesquare.java
字号:
// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name: movesquare.java
import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class movesquare extends Applet implements ActionListener
{
Panel p;
JButton b[];
Label l;
int cnt;
boolean flag;
Image ig;
ImageIcon h;
public movesquare()
{
}
public void init()
{
ig=getImage(getCodeBase(),"01.jpg");
h=new ImageIcon(ig);
p = new Panel();
l = new Label("ready");
cnt = 0;
flag = false;
b = new JButton[16];
GridLayout Grid = new GridLayout(4, 4, 0, 0);
p.setLayout(Grid);
for(int i = 15; i > -1; i--)
{
cnt++;
if(i != 0)
{b[i] = new JButton(Integer.toString(i),h);
}
else
b[i] = new JButton("");
b[i].addActionListener(this);
p.add(b[i]);
}
setLayout(new BorderLayout());
add("North", l);
add("Center", p);
cnt = 0;
}
public void actionPerformed(ActionEvent e)
{
for(int j = 0; j < 16; j++)
{
if(b[j].getLabel() != e.getActionCommand())
continue;
if(cnt == j - 1 || cnt == j + 1 || cnt == j + 4 || cnt == j - 4)
{
b[cnt].setLabel(b[j].getActionCommand());
b[cnt].setActionCommand(b[j].getActionCommand());
b[cnt].setIcon(b[j].getIcon());
b[j].setLabel("");
b[j].setActionCommand("");
b[j].setIcon(new ImageIcon());
cnt = j;
l.setText("继续,还未成功!");
break;
}
l.setText("您不能移动这个方格!");
}
flag = true;
int m = 1;
do
{
if(m >= 16)
break;
if(b[m].getLabel().equals(Integer.toString((15 - m) + 1)))
m++;
else
{flag=false;
break;
}
} while(true);
if(flag)//if中使用object.equals(object)
l.setText("成功拉~~");
}
}
//<applet code="movesquare.class" Width="650" Height="650"></applet>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -