package package14;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* This are the borland classes only use for the GUI . do not worry
about them
since the functionality is still the PURE java*/
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
public class Shuffle extends Applet {
XYLayout xYLayout1 = new XYLayout();
boolean isStandalone = false;
ButtonControl but2 = new ButtonControl();
ButtonControl but1 = new ButtonControl();
ButtonControl but3 = new ButtonControl();
ButtonControl but4 = new ButtonControl();
ButtonControl but5 = new ButtonControl();
ButtonControl but6 = new ButtonControl();
ButtonControl but7 = new ButtonControl();
ButtonControl but8 = new ButtonControl();
ButtonControl but9 = new ButtonControl();
ButtonControl but10 = new ButtonControl();
ButtonControl but11 = new ButtonControl();
ButtonControl but12 = new ButtonControl();
ButtonControl but13 = new ButtonControl();
ButtonControl but14 = new ButtonControl();
ButtonControl but15 = new ButtonControl();
BevelPanel bevelPanel1 = new BevelPanel();
ButtonControl butNull = new ButtonControl();
ButtonControl butShuffle = new ButtonControl();
Label lblClicks = new Label();
Label lblClickNum = new Label();
//DECLARATIONS:
int ArryIndex[][];
int iCount = 1;
// to fill the array start with 1
int iClicked = 0;
// Clicked row index
int jClicked = 0;
// Clicked column index
int iNull = 100;
// the iNull =9
int iClickNum = 0;
// Number of the cllicks
//CONSTANTS:
final int iNumberOfHorzButs = 5; // Vertical rows
final int iNumberOfVertButs = 5; // Horizontal rows
final int UPPER_LEFT_CLICKED = 11; //constant to indentify
location
final int UPPER_RIGHT_CLICKED = 14; //constant to indentify
location
final int LOWER_LEFT_CLICKED = 41; //constant to indentify
location
final int LOWER_RIGHT_CLICKED = 44; //constant to indentify
location
final int UPPER_ROW_CLICKED = 4; //constant
to indentify location
final int LOWER_ROW_CLICKED = 5; //constant
to indentify location
final int LEFT_ROW_CLICKED = 6; //constant
to indentify location
final int RIGHT_ROW_CLICKED = 7;
Label lblStatus = new Label();
//constant to indentify location
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def)
:
(getParameter(key) != null ? getParameter(key)
: def);
}
public void paint(Graphics g){
//Display the click numbers:
lblClickNum.setText(String.valueOf(iClickNum));
//but1:
if(ArryIndex[1][1] == 100){
but1.setLabel("");
}
else{
but1.setLabel(String.valueOf(ArryIndex[1][1]));
}
//but2:
if(ArryIndex[1][2] == 100){
but2.setLabel("");
}
else{
but2.setLabel(String.valueOf(ArryIndex[1][2]));
}
//but3:
if(ArryIndex[1][3] == 100){
but3.setLabel("");
}
else{
but3.setLabel(String.valueOf(ArryIndex[1][3]));
}
//but4:
if(ArryIndex[1][4] == 100){
but4.setLabel("");
}
else{
but4.setLabel(String.valueOf(ArryIndex[1][4]));
}
//but5:
if(ArryIndex[2][1] == 100){
but5.setLabel("");
}
else{
but5.setLabel(String.valueOf(ArryIndex[2][1]));
}
//but6:
if(ArryIndex[2][2] == 100){
but6.setLabel("");
}
else{
but6.setLabel(String.valueOf(ArryIndex[2][2]));
}
//but7:
if(ArryIndex[2][3] == 100){
but7.setLabel("");
}
else{
but7.setLabel(String.valueOf(ArryIndex[2][3]));
}
//but8:
if(ArryIndex[2][4] == 100){
but8.setLabel("");
}
else{
but8.setLabel(String.valueOf(ArryIndex[2][4]));
}
//but9:
if(ArryIndex[3][1] == 100){
but9.setLabel("");
}
else{
but9.setLabel(String.valueOf(ArryIndex[3][1]));
}
//but10:
if(ArryIndex[3][2] == 100){
but10.setLabel("");
}
else{
but10.setLabel(String.valueOf(ArryIndex[3][2]));
}
//but11:
if(ArryIndex[3][3] == 100){
but11.setLabel("");
}
else{
but11.setLabel(String.valueOf(ArryIndex[3][3]));
}
//but12:
if(ArryIndex[3][4] == 100){
but12.setLabel("");
}
else{
but12.setLabel(String.valueOf(ArryIndex[3][4]));
}
//but13:
if(ArryIndex[4][1] == 100){
but13.setLabel("");
}
else{
but13.setLabel(String.valueOf(ArryIndex[4][1]));
}
//but14:
if(ArryIndex[4][2] == 100){
but14.setLabel("");
}
else{
but14.setLabel(String.valueOf(ArryIndex[4][2]));
}
//but15:
if(ArryIndex[4][3] == 100){
but15.setLabel("");
}
else{
but15.setLabel(String.valueOf(ArryIndex[4][3]));
}
//butNull:
if(ArryIndex[4][4] == 100){
butNull.setLabel("");
}
else{
butNull.setLabel(String.valueOf(ArryIndex[4][4]));
}
//See if the game is over i.e all the numbers are
//arranged in sequential order:
if ((int)Integer.parseInt(lblClickNum.getText())
>0 &&
(ArryIndex[1][1] == 1)
&&
(ArryIndex[1][2] == 2)
&&
(ArryIndex[1][3] == 3)
&&
(ArryIndex[1][4] == 4)
&&
(ArryIndex[2][1] == 5)
&&
(ArryIndex[2][2] == 6)
&&
(ArryIndex[2][3] == 7)
&&
(ArryIndex[2][4] == 8)
&&
(ArryIndex[3][1] == 9)
&&
(ArryIndex[3][2] == 10)
&&
(ArryIndex[3][3] == 11)
&&
(ArryIndex[3][4] == 12)
&&
(ArryIndex[4][1] == 13)
&&
(ArryIndex[4][2] == 14)
&&
(ArryIndex[4][3] == 15)
&&
(ArryIndex[4][4] == 100))
{
System.out.println("Game Over");
lblClickNum.setText(String.valueOf(iClickNum));
if (((int)Integer.parseInt(lblClickNum.getText()))
<= 100 ){
lblStatus.setText("GameOver With Very Good
Score;-)");
}//VeryGood
if (((int)Integer.parseInt(lblClickNum.getText()))
> 100 &&
((int)Integer.parseInt(lblClickNum.getText()))
<= 200
){
lblStatus.setText("GameOver With Average Score
:-)");
}//Average
if (((int)Integer.parseInt(lblClickNum.getText()))
> 200 ){
lblStatus.setText("Score Could Be Better :-(");
}//Poor
}// if arrayIndex
}//paint
//Construct the applet
public Shuffle() {
}
//Initialize the applet
public void init() {
try { jbInit(); } catch (Exception e) { e.printStackTrace();
}
}
//Component initialization
public void jbInit() throws Exception{
xYLayout1.setWidth(336);
xYLayout1.setHeight(309);
but2.setBackground(Color.black);
but2.setForeground(Color.green);
but2.setFont(new Font("TimesRoman", 1, 18));
but2.setLabel("2");
but2.addActionListener(new Shuffle_but2_actionAdapter(this));
but1.setForeground(Color.green);
but1.setBackground(Color.black);
but1.setFont(new Font("TimesRoman", 1, 18));
but1.setLabel("1");
but1.addActionListener(new Shuffle_but1_actionAdapter(this));
but3.setForeground(Color.green);
but3.setBackground(Color.black);
but3.setFont(new Font("TimesRoman", 1, 18));
but3.setLabel("3");
but3.addActionListener(new Shuffle_but3_actionAdapter(this));
but4.setForeground(Color.green);
but4.setBackground(Color.black);
but4.setFont(new Font("TimesRoman", 1, 18));
but4.setLabel("4");
but4.addActionListener(new Shuffle_but4_actionAdapter(this));
but5.setForeground(Color.green);
but5.setBackground(Color.black);
but5.setFont(new Font("TimesRoman", 1, 18));
but5.setLabel("5");
but5.addActionListener(new Shuffle_but5_actionAdapter(this));
but6.setForeground(Color.green);
but6.setBackground(Color.black);
but6.setFont(new Font("TimesRoman", 1, 18));
but6.setLabel("6");
but6.addActionListener(new Shuffle_but6_actionAdapter(this));
but7.setForeground(Color.green);
but7.setBackground(Color.black);
but7.setFont(new Font("TimesRoman", 1, 18));
but7.setLabel("7");
but7.addActionListener(new Shuffle_but7_actionAdapter(this));
but8.setForeground(Color.green);
but8.setBackground(Color.black);
but8.setFont(new Font("TimesRoman", 1, 18));
but8.setLabel("8");
but8.addActionListener(new Shuffle_but8_actionAdapter(this));
but9.setForeground(Color.green);
but9.setBackground(Color.black);
but9.setFont(new Font("TimesRoman", 1, 18));
but9.setLabel("9");
but9.addActionListener(new Shuffle_but9_actionAdapter(this));
but10.setForeground(Color.green);
but10.setBackground(Color.black);
but10.setFont(new Font("TimesRoman", 1, 18));
but10.setLabel("10");
but10.addActionListener(new Shuffle_but10_actionAdapter(this));
but11.setForeground(Color.green);
but11.setBackground(Color.black);
but11.setFont(new Font("TimesRoman", 1, 18));
but11.setLabel("11");
but11.addActionListener(new Shuffle_but11_actionAdapter(this));
but12.setForeground(Color.green);
but12.setBackground(Color.black);
but12.setFont(new Font("TimesRoman", 1, 18));
but12.setLabel("12");
but12.addActionListener(new Shuffle_but12_actionAdapter(this));
but13.setForeground(Color.green);
but13.setBackground(Color.black);
but13.setFont(new Font("TimesRoman", 1, 18));
but13.setLabel("13");
but13.addActionListener(new Shuffle_but13_actionAdapter(this));
but14.setForeground(Color.green);
but14.setBackground(Color.black);
but14.setFont(new Font("TimesRoman", 1, 18));
but14.setLabel("14");
but14.addActionListener(new Shuffle_but14_actionAdapter(this));
but15.setForeground(Color.green);
but15.setBackground(Color.black);
but15.setFont(new Font("TimesRoman", 1, 18));
but15.setLabel("15");
but15.addActionListener(new Shuffle_but15_actionAdapter(this));
bevelPanel1.setBackground(new Color(192, 255, 192));
butNull.setBackground(Color.black);
butNull.setFont(new Font("TimesRoman", 1, 18));
butNull.setForeground(Color.green);
butNull.setLabel("");
butNull.addActionListener(new Shuffle_butNull_actionAdapter(this));
butShuffle.setBackground(Color.white);
butShuffle.setFont(new Font("TimesRoman", 1, 18));
butShuffle.setForeground(Color.red);
butShuffle.setLabel("Shuffle");
butShuffle.addActionListener(new Shuffle_butShuffle_actionAdapter(this));
lblClicks.setFont(new Font("TimesRoman", 1, 13));
lblClicks.setText("Clicks:");
lblClickNum.setFont(new Font("TimesRoman", 1, 15));
lblClickNum.setText("0");
lblStatus.setForeground(Color.red);
lblStatus.setFont(new Font("TimesRoman", 1, 13));
lblStatus.setBackground(Color.white);
this.setLayout(xYLayout1);
this.add(lblStatus, new XYConstraints(48, 260, 217,
31));
this.add(bevelPanel1, new XYConstraints(48, 15,
217, 275));
bevelPanel1.add(but1, new XYConstraints(11, 16,
46, 44));
bevelPanel1.add(but2, new XYConstraints(59, 16,
46, 44));
bevelPanel1.add(but5, new XYConstraints(11, 62,
46, 44));
bevelPanel1.add(but3, new XYConstraints(107, 16,
46, 44));
bevelPanel1.add(but4, new XYConstraints(155, 16,
46, 44));
bevelPanel1.add(but6, new XYConstraints(59, 62,
46, 44));
bevelPanel1.add(but7, new XYConstraints(107, 62,
46, 44));
bevelPanel1.add(but8, new XYConstraints(155, 62,
46, 44));
bevelPanel1.add(but9, new XYConstraints(11, 109,
46, 44));
bevelPanel1.add(but10, new XYConstraints(59, 109,
46, 44));
bevelPanel1.add(but11, new XYConstraints(107, 109,
46, 44));
bevelPanel1.add(but12, new XYConstraints(155, 109,
46, 44));
bevelPanel1.add(but13, new XYConstraints(11, 155,
46, 44));
bevelPanel1.add(but14, new XYConstraints(59, 155,
46, 44));
bevelPanel1.add(but15, new XYConstraints(107, 155,
46, 44));
bevelPanel1.add(butNull, new XYConstraints(155,
156, 46, 43));
bevelPanel1.add(butShuffle, new XYConstraints(12,
207, 93, 33));
bevelPanel1.add(lblClicks, new XYConstraints(109,
214, 44, 22));
bevelPanel1.add(lblClickNum, new XYConstraints(160,
216, 35, 18));
ArryIndex = new int[iNumberOfHorzButs][iNumberOfVertButs];
//Initialize the arrayvalues or populate it initially:
for(int i = 1;i < iNumberOfHorzButs; i++){
for(int j = 1;j < iNumberOfVertButs; j++){
ArryIndex[i][j] = iCount;
iCount++;
}//looping through vertical rows
}//looping through horizontal rows
//Set the null value in the last:
ArryIndex[iNumberOfHorzButs-1][iNumberOfVertButs-1]
= 100;
}//jbinit()
//Start the applet
public void start() {
}
//Stop the applet
public void stop() {
}
//Destroy the applet
public void destroy() {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
void but1_actionPerformed(ActionEvent e) {
iClicked = 1; //the clicked row index
jClicked = 1; //the clicked column index
iClickNum +=1; //increase the number of clicks
ShuffleBoundary(UPPER_LEFT_CLICKED);
}//action for But1
/**
-------------------------------------------------------------
NAME : ShuffleBoundary
INPUT : int
CONSTANT indicating the location of the button clicked
OUTPUT: void
but change the ArryIndex
DESCRIPTION: Takes the location and checks
the surrounding cells for the 100 number and swaps
-------------------------------------------------------------
*/
public void ShuffleBoundary(int iLocation){
switch(iLocation){
case UPPER_LEFT_CLICKED :
System.out.println("Upper
Left Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [1][1]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if(ArryIndex[1][2] == iNull){
System.out.println("Found
at :" + ArryIndex[1][2]);
Swap(1,2);
repaint();
}
else if(ArryIndex[2][1] == iNull){
System.out.println("Found
at :" + ArryIndex[2][1]);
Swap(2,1);
repaint();
}
break;
case UPPER_RIGHT_CLICKED :
System.out.println("Upper
Right Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [1][4]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if(ArryIndex[1][3] == iNull){
System.out.println("Found
at :" + ArryIndex[1][3]);
Swap(1,3);
repaint();
}
else if(ArryIndex[2][4] == iNull){
System.out.println("Found
at :" + ArryIndex[2][4]);
Swap(2,4);
repaint();
}
break;
case LOWER_LEFT_CLICKED :
System.out.println("Lower
Left Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [4][1]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if(ArryIndex[3][1] == iNull){
System.out.println("Found
at :" + ArryIndex[3][1]);
Swap(3,1);
repaint();
}
else if(ArryIndex[4][2] == iNull){
System.out.println("Found
at :" + ArryIndex[4][2]);
Swap(4,2);
repaint();
}
break;
case LOWER_RIGHT_CLICKED :
System.out.println("Lower
Right Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [4][4]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if(ArryIndex[3][4] == iNull){
System.out.println("Found
at :" + ArryIndex[3][4]);
Swap(3,4);
repaint();
}
else if(ArryIndex[4][3] == iNull){
System.out.println("Found
at :" + ArryIndex[4][3]);
Swap(4,3);
repaint();
}
break;
case UPPER_ROW_CLICKED :
System.out.println("Upper
Row Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [1][2]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 1)&&(jClicked
== 2)){
if(ArryIndex[1][1] == iNull){
System.out.println("Found
at :" + ArryIndex[1][1]);
Swap(1,1);
repaint();
}
else if(ArryIndex[1][3] == iNull){
System.out.println("Found
at :" + ArryIndex[1][3]);
Swap(1,3);
repaint();
}
else if(ArryIndex[2][2] == iNull){
System.out.println("Found
at :" + ArryIndex[2][2]);
Swap(2,2);
repaint();
}
}//if[1][2]
//Check for the [1][3]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 1)&&(jClicked
== 3)){
if(ArryIndex[1][2] == iNull){
System.out.println("Found
at :" + ArryIndex[1][2]);
Swap(1,2);
repaint();
}
else if(ArryIndex[1][4] == iNull){
System.out.println("Found
at :" + ArryIndex[1][4]);
Swap(1,4);
repaint();
}
else if(ArryIndex[2][3] == iNull){
System.out.println("Found
at :" + ArryIndex[2][3]);
Swap(2,3);
repaint();
}
}//if[1][3]
break;
case LOWER_ROW_CLICKED :
System.out.println("Lower
Row Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [4][2]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 4)&&(jClicked
== 2)){
if(ArryIndex[4][1] == iNull){
System.out.println("Found
at :" + ArryIndex[4][1]);
Swap(4,1);
repaint();
}
else if(ArryIndex[3][2] == iNull){
System.out.println("Found
at :" + ArryIndex[3][2]);
Swap(3,2);
repaint();
}
else if(ArryIndex[4][3] == iNull){
System.out.println("Found
at :" + ArryIndex[4][3]);
Swap(4,3);
repaint();
}
}//if[4][2]
//Check for the [4][3]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 4)&&(jClicked
== 3)){
if(ArryIndex[4][2] == iNull){
System.out.println("Found
at :" + ArryIndex[4][2]);
Swap(4,2);
repaint();
}
else if(ArryIndex[3][3] == iNull){
System.out.println("Found
at :" + ArryIndex[3][3]);
Swap(3,3);
repaint();
}
else if(ArryIndex[4][4] == iNull){
System.out.println("Found
at :" + ArryIndex[4][4]);
Swap(4,4);
repaint();
}
}//if[4][3]
break;
case LEFT_ROW_CLICKED :
System.out.println("Left
Row Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [1][2]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 2)&&(jClicked
== 1)){
if(ArryIndex[1][1] == iNull){
System.out.println("Found
at :" + ArryIndex[1][1]);
Swap(1,1);
repaint();
}
else if(ArryIndex[2][2] == iNull){
System.out.println("Found
at :" + ArryIndex[2][2]);
Swap(2,2);
repaint();
}
else if(ArryIndex[3][1] == iNull){
System.out.println("Found
at :" + ArryIndex[3][1]);
Swap(3,1);
repaint();
}
}//if[2][1]
//Check for the [3][1]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 3)&&(jClicked
== 1)){
if(ArryIndex[2][1] == iNull){
System.out.println("Found
at :" + ArryIndex[2][1]);
Swap(2,1);
repaint();
}
else if(ArryIndex[3][2] == iNull){
System.out.println("Found
at :" + ArryIndex[3][2]);
Swap(3,2);
repaint();
}
else if(ArryIndex[4][1] == iNull){
System.out.println("Found
at :" + ArryIndex[4][1]);
Swap(4,1);
repaint();
}
}//if[3][1]
break;
case RIGHT_ROW_CLICKED :
System.out.println("Right
Row Clicked");
System.out.println(iClicked
+ ":" + jClicked);
//Check for the [2][4]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 2)&&(jClicked
== 4)){
if(ArryIndex[1][4] == iNull){
System.out.println("Found
at :" + ArryIndex[1][4]);
Swap(1,4);
repaint();
}
else if(ArryIndex[2][3] == iNull){
System.out.println("Found
at :" + ArryIndex[2][3]);
Swap(2,3);
repaint();
}
else if(ArryIndex[3][4] == iNull){
System.out.println("Found
at :" + ArryIndex[3][4]);
Swap(3,4);
repaint();
}
}//if[2][4]
//Check for the [3][4]:
System.out.println("Clicked item:"
+ ArryIndex[iClicked][jClicked]);
if((iClicked == 3)&&(jClicked
== 4)){
if(ArryIndex[2][4] == iNull){
System.out.println("Found
at :" + ArryIndex[2][4]);
Swap(2,4);
repaint();
}
else if(ArryIndex[3][3] == iNull){
System.out.println("Found
at :" + ArryIndex[3][3]);
Swap(3,3);
repaint();
}
else if(ArryIndex[4][4] == iNull){
System.out.println("Found
at :" + ArryIndex[4][4]);
Swap(4,4);
repaint();
}
}//if[3][4]
break;
}//switch
}//ShuffleBoundary
/**
-------------------------------------------------------------
NAME : ShuffleMiddle
INPUT : int
CONSTANT indicating the location of the button clicked
OUTPUT: void
but change the ArryIndex
DESCRIPTION: Takes the location and checks
the surrounding cells for the 100 number and swaps
-------------------------------------------------------------
*/
public void ShuffleMiddle(){
//Check for the [2][2]:
System.out.println("Clicked item:" + ArryIndex[iClicked][jClicked]);
if((iClicked == 2)&&(jClicked == 2)){
if(ArryIndex[1][2] == iNull){
System.out.println("Found
at :" + ArryIndex[1][2]);
Swap(1,2);
repaint();
}
else if(ArryIndex[2][3] == iNull){
System.out.println("Found
at :" + ArryIndex[2][3]);
Swap(2,3);
repaint();
}
else if(ArryIndex[3][2] == iNull){
System.out.println("Found
at :" + ArryIndex[3][2]);
Swap(3,2);
repaint();
}
else if(ArryIndex[2][1] == iNull){
System.out.println("Found
at :" + ArryIndex[2][1]);
Swap(2,1);
repaint();
}
}//if[2][2]
//Check for the [2][3]:
System.out.println("Clicked item:" + ArryIndex[iClicked][jClicked]);
if((iClicked == 2)&&(jClicked == 3)){
if(ArryIndex[1][3] == iNull){
System.out.println("Found
at :" + ArryIndex[1][3]);
Swap(1,3);
repaint();
}
else if(ArryIndex[2][4] == iNull){
System.out.println("Found
at :" + ArryIndex[2][4]);
Swap(2,4);
repaint();
}
else if(ArryIndex[3][3] == iNull){
System.out.println("Found
at :" + ArryIndex[3][3]);
Swap(3,3);
repaint();
}
else if(ArryIndex[2][2] == iNull){
System.out.println("Found
at :" + ArryIndex[2][2]);
Swap(2,2);
repaint();
}
}//if[2][3]
//Check for the [3][3]:
System.out.println("Clicked item:" + ArryIndex[iClicked][jClicked]);
if((iClicked == 3)&&(jClicked == 3)){
if(ArryIndex[2][3] == iNull){
System.out.println("Found
at :" + ArryIndex[2][3]);
Swap(2,3);
repaint();
}
else if(ArryIndex[3][4] == iNull){
System.out.println("Found
at :" + ArryIndex[3][4]);
Swap(3,4);
repaint();
}
else if(ArryIndex[4][3] == iNull){
System.out.println("Found
at :" + ArryIndex[4][3]);
Swap(4,3);
repaint();
}
else if(ArryIndex[3][2] == iNull){
System.out.println("Found
at :" + ArryIndex[3][2]);
Swap(3,2);
repaint();
}
}//if[3][3]
//Check for the [3][2]:
System.out.println("Clicked item:" + ArryIndex[iClicked][jClicked]);
if((iClicked == 3)&&(jClicked == 2)){
if(ArryIndex[2][2] == iNull){
System.out.println("Found
at :" + ArryIndex[2][2]);
Swap(2,2);
repaint();
}
else if(ArryIndex[3][3] == iNull){
System.out.println("Found
at :" + ArryIndex[3][3]);
Swap(3,3);
repaint();
}
else if(ArryIndex[4][2] == iNull){
System.out.println("Found
at :" + ArryIndex[4][2]);
Swap(4,2);
repaint();
}
else if(ArryIndex[3][1] == iNull){
System.out.println("Found
at :" + ArryIndex[3][1]);
Swap(3,1);
repaint();
}
}//if[3][2]
}//ShuffleMiddle()
/**
-------------------------------------------------------------
INPUT: int,int
OUTPUT:void
DESCRIPTION:Swaping values
-------------------------------------------------------------
*/
public void Swap(int iFound,int jFound){
int iTemp;
iTemp = ArryIndex[iClicked][jClicked];
ArryIndex[iClicked][jClicked] = ArryIndex[iFound][jFound];
ArryIndex[iFound][jFound] = iTemp;
}//paint()
void but4_actionPerformed(ActionEvent e) {
iClicked = 1;
jClicked = 4;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(UPPER_RIGHT_CLICKED);
}//but4
void but13_actionPerformed(ActionEvent e) {
iClicked = 4;
jClicked = 1;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(LOWER_LEFT_CLICKED);
}//but3
void but2_actionPerformed(ActionEvent e) {
iClicked = 1;
jClicked = 2;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(UPPER_ROW_CLICKED);
}//but2
void butNull_actionPerformed(ActionEvent e) {
iClicked = 4;
jClicked = 4;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(LOWER_RIGHT_CLICKED);
}//butNull
void but3_actionPerformed(ActionEvent e) {
iClicked = 1;
jClicked = 3;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(UPPER_ROW_CLICKED);
}//but3
void but5_actionPerformed(ActionEvent e) {
iClicked = 2;
jClicked = 1;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(LEFT_ROW_CLICKED);
}//but5
void but6_actionPerformed(ActionEvent e) {
iClicked = 2;
jClicked = 2;
iClickNum +=1; //increase the number
of clicks
System.out.println(iClicked + ":" + jClicked);
ShuffleMiddle();
}//but6
void but7_actionPerformed(ActionEvent e) {
iClicked = 2;
jClicked = 3;
iClickNum +=1; //increase the number
of clicks
System.out.println(iClicked + ":" + jClicked);
ShuffleMiddle();
}//but7
void but8_actionPerformed(ActionEvent e) {
iClicked = 2;
jClicked = 4;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(RIGHT_ROW_CLICKED);
}//but8
void but9_actionPerformed(ActionEvent e) {
iClicked = 3;
jClicked = 1;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(LEFT_ROW_CLICKED);
}//but9
void but10_actionPerformed(ActionEvent e) {
iClicked = 3;
jClicked = 2;
iClickNum +=1; //increase the number
of clicks
System.out.println(iClicked + ":" + jClicked);
ShuffleMiddle();
}//but10
void but11_actionPerformed(ActionEvent e) {
iClicked = 3;
jClicked = 3;
iClickNum +=1; //increase the number
of clicks
System.out.println(iClicked + ":" + jClicked);
ShuffleMiddle();
}//but11
void but14_actionPerformed(ActionEvent e) {
iClicked = 4;
jClicked = 2;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(LOWER_ROW_CLICKED);
}//14
void but15_actionPerformed(ActionEvent e) {
iClicked = 4;
jClicked = 3;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(LOWER_ROW_CLICKED);
}//but15
void but12_actionPerformed(ActionEvent e) {
iClicked = 3;
jClicked = 4;
iClickNum +=1; //increase the number
of clicks
ShuffleBoundary(RIGHT_ROW_CLICKED);
}//but12
void butShuffle_actionPerformed(ActionEvent e) {
iClickNum = 0;
//reset the counter to Zero
lblStatus.setText("");
//reset the Status message
ArrangeRandomlyArry();
repaint();
//Again Show the shuffled
//numbers
}//butShuffle_actionPerformed..
/**
-------------------------------------------------------------
NAME : ArrangeRandomlyArry
INPUT : void
OUTPUT: void
DESCRIPTION : generate a random number and
interchange the arryindex arrays to
show that effect.
-------------------------------------------------------------
*/
public void ArrangeRandomlyArry(){
int iRandomNum1 = 0; //arrayindex selected
for first item
int jRandomNum1 = 0; //arrayindex selected
for first item
int iRandomNum2 = 0; //arrayindex selected
for second item
int jRandomNum2 = 0; //arrayindex selected
for second item
int iNum1 = 0;
int iNum2 = 0;
int iTemp = 0;
for(int iteration = 0;iteration <=10;iteration
++){
iRandomNum1 = (int)(Math.random()*4);
//Generate random Indices
jRandomNum1 = (int)(Math.random()*4);
//Generate random Indices
iRandomNum2 = (int)(Math.random()*4);
//Generate random Indices
jRandomNum2 = (int)(Math.random()*4);
//Generate random Indices
iNum1 = (int)(Math.random()*16);
//Generate first random num
iNum2 = (int)(Math.random()*16);
//Generate second random num
//Swap the numbers:
iTemp = ArryIndex[iRandomNum1+1][jRandomNum1+1];
ArryIndex[iRandomNum1+1][jRandomNum1+1]
= ArryIndex[iRandomNum2+1][jRandomNum2+1];
ArryIndex[iRandomNum2+1][jRandomNum2+1]
= iTemp;
}//number of iterations
}//ArrangeRandomlyArry()
}//applet
// Action Classes:-----------------------------------------------
class Shuffle_but1_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but1_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but1_actionPerformed(e);
}
}
class Shuffle_but4_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but4_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but4_actionPerformed(e);
}
}
class Shuffle_but13_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but13_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but13_actionPerformed(e);
}
}
class Shuffle_but2_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but2_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but2_actionPerformed(e);
}
}
class Shuffle_butNull_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_butNull_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.butNull_actionPerformed(e);
}
}
class Shuffle_but3_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but3_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but3_actionPerformed(e);
}
}
class Shuffle_but5_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but5_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but5_actionPerformed(e);
}
}
class Shuffle_but6_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but6_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but6_actionPerformed(e);
}
}
class Shuffle_but7_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but7_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but7_actionPerformed(e);
}
}
class Shuffle_but8_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but8_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but8_actionPerformed(e);
}
}
class Shuffle_but9_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but9_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but9_actionPerformed(e);
}
}
class Shuffle_but10_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but10_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but10_actionPerformed(e);
}
}
class Shuffle_but11_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but11_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but11_actionPerformed(e);
}
}
class Shuffle_but14_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but14_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but14_actionPerformed(e);
}
}
class Shuffle_but15_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but15_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but15_actionPerformed(e);
}
}
class Shuffle_but12_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_but12_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.but12_actionPerformed(e);
}//actionPerformed(ActionEvent e)
}
class Shuffle_butShuffle_actionAdapter implements java.awt.event.ActionListener{
Shuffle adaptee;
Shuffle_butShuffle_actionAdapter(Shuffle adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.butShuffle_actionPerformed(e);
}
}
back
.