Hi I am trying to create a slider puzzle where i have 9 buttons numbered 1 - 8 and then a blank one. I am able to create all my buttons but I am unsure as how to make the numbers move from one button to another.. any hints or help would be greatly appreciated. Im very new to all this. thanks
CODE
//i want this project to display 9 tiles that can be moveble. it is a puzzle game.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*; // needed for containers
import java.awt.event.*;
import java.util.Vector;
import java.io.*;
class PhilsPuzzle extends JFrame implements ActionListener, ItemListener {
JButton one = new JButton("1");
JButton two = new JButton("2");
JButton three = new JButton("3");
JButton four = new JButton("4");
JButton five = new JButton("5");
JButton six = new JButton("6");
JButton seven = new JButton("7");
JButton eight = new JButton("8");
JButton nine = new JButton("");
public PhilsPuzzle() {
// graphics
super("Phillys Puzzling Puzzler MaBobby");
setSize(750,500);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
JPanel myScreen = new JPanel();
BorderLayout layout = new BorderLayout();// main window
myScreen.setLayout(layout);
JPanel northscreen = new JPanel();
FlowLayout northLayout = new FlowLayout();
northscreen.setLayout(northLayout);
JPanel centreScreen = new JPanel();
GridBagLayout flowManager = new GridBagLayout();
GridBagConstraints pos = new GridBagConstraints();
centreScreen.setLayout(flowManager);
myScreen.add("North", northscreen);
myScreen.add("Center", centreScreen);
one.addActionListener(this);
two.addActionListener(this);
three.addActionListener(this);
four.addActionListener(this);
five.addActionListener(this);
six.addActionListener(this);
seven.addActionListener(this);
eight.addActionListener(this);
nine.addActionListener(this); // listeners for all my buttons etc
centreScreen.add(one); // adding content to the window
centreScreen.add(two);
centreScreen.add(three);
centreScreen.add(four);
centreScreen.add(five);
centreScreen.add(six);
centreScreen.add(seven);
centreScreen.add(eight);
centreScreen.add(nine);
pos.gridx = 0; pos.gridy = 1;
centreScreen.add(one, pos);
pos.gridx = 1; pos.gridy = 1;
centreScreen.add(two, pos);
pos.gridx = 2; pos.gridy = 1;
centreScreen.add(three, pos);
pos.gridx = 0; pos.gridy = 2;
centreScreen.add(four, pos);
pos.gridx = 1; pos.gridy = 2;
centreScreen.add(five, pos);
pos.gridx = 2; pos.gridy = 2;
centreScreen.add(six, pos);
pos.gridx = 0; pos.gridy = 3;
centreScreen.add(seven, pos);
pos.gridx = 1; pos.gridy = 3;
centreScreen.add(eight, pos);
pos.gridx = 2; pos.gridy = 3;
centreScreen.add(nine, pos);
setContentPane(myScreen);
setVisible(true);
} //end of graphic cd
public void actionPerformed(ActionEvent event) {
}// end of action performed
public void itemStateChanged(ItemEvent event) {
}
public static void main (String args[]) {
PhilsPuzzle puzzle = new PhilsPuzzle();
}
}