728x90 AdSpace

Trending

puzzle game in java

We have seen this game in most of the mobiles.
It will be fun if we design this game ourselves and play it on our own PC!!! Is'nt it??
So lets get started!!!
How to Play:
This is a kind of thinking game in which we have to arrange all the boxes according to the numerical order
by moving the it up and down instead of clicking and swapping it!!
Here goes the code :-
/*
<applet code="MatrixMultiplication.class" height=300 width=300></applet>
*/

import java.awt.*;
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MatrixMultiplication extends Applet{
JPanel panel;
JButton button[];
int swap1=-1;
int swap2;
int j;
public void init(){
panel=new JPanel(new GridLayout(3,3));
}
public void start(){
button=new JButton[9];
Font f=new Font("Arial",Font.BOLD,50);
add(panel);
for(int i=0;i<9;i++)
{
button[i]=new JButton(i+"");
button[i].setFont(f);
button[i].addActionListener(new Swaping(i));
panel.add(button[i]);
}
}
class Swaping implements ActionListener{
int i;
Swaping(int i){this.i=i;}
public void actionPerformed(ActionEvent aef){
button[i].setEnabled(false);
if(swap1==-1)
{j=i;swap1=Integer.parseInt(button[i].getText());}
else
{
swap2=Integer.parseInt(button[i].getText());
button[j].setText(swap2+"");
button[i].setText(swap1+"");
button[i].setEnabled(true);
button[j].setEnabled(true);
swap1=-1;
}
}
}
}

Click Here to download .class files.
Try this out:-



puzzle game in java Reviewed by B AProgrammer on 11:25 Rating: 5 We have seen this game in most of the mobiles. It will be fun if we design this game ourselves and play it on our own PC!!! Is'nt it??...

No comments: