?? 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("繼續(xù),還未成功!");
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>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -