Hi,
I am new in java programming and I would like to make an applet so as to insert into a webpage.
The applet I am trying to make is a game called slided squares.
There are 8 squares (with numbers 1,2,3 ... 8 ) and an empty.
If I click on a square near empty square, it is moved.
Also there is a move counter.
when I find all the squares with arithmetic order the program appears a congratulations dialog message.
Here is the game :
http://leepoint.net/notes-java/examp...idepuzzle.html
and my code until now is :
Code:import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
public class SApplet extends Applet implements ActionListener {
TextField input,output;
Label label1,label2, label3, label4, label5, label6;
JButton[] buttons = new JButton[9];
JLabel lbl;
int num, sum = 0,i;
int[] test = {2,1,3,8,7,5,6,4,0};
int metrhths = 0;
Label metrhthsl;
public void init(){
GridLayout layout = new GridLayout(4,3);
setLayout(layout);
Label keno = new Label("");
Label keno2 = new Label("");
metrhthsl = new Label("moves: "+Integer.toString(metrhths));
for(i=0;i<9;i++){
buttons[i]=new JButton(Integer.toString(test[i]));
add(buttons[i]);
buttons[i].addActionListener(this);
}
add(keno);
add(metrhthsl);
add(keno2);
}
public int getArrayIndex(int[] myArray, int myObject)
{
int ArraySize = Array.getLength(myArray);
for (int i = 0; i < ArraySize; i++)
{
if (myArray[i] == myObject)
{
return(i);
}
}
return(-1);
}
public void actionPerformed(ActionEvent ae){
metrhths +=1;
metrhthsl.setText("moves: "+Integer.toString(metrhths));
//add(metrhthsl);
Object source = ae.getSource();
String label = ae.getActionCommand();
int labelint = Integer.parseInt(label);
int index=getArrayIndex(test, labelint);
if((buttons[index+1].getText()).equals("0")){
// if(source==buttons[1]){
int[] test2 = {1,1,3,8,7,5,6,4,0};
for(i=0;i<9;i++){
buttons[i].setText(Integer.toString(test2[i]));
}
}
}
}

