package Puzzle; import java.awt.event.*; /** * Puzzle -- the application class for the N-puzzle * Gui/App * */ public class PuzzleApp implements ActionListener { /** * constructs a Puzzle Application for a size X size board * @param size the size of the board * */ public PuzzleApp(int size,PuzzleTileFactory ptf) { mySize = size; myFactory = ptf; } /** * attach a gui to the application (these will be tightly coupled) * @param gui is the attached gui * */ public void addGUI(PuzzleGui gui) { } /** * search on board for the string s */ } /** * performs the action associated with this * class being an ActionListener * * @param e the ActionEvent listed to */ public void actionPerformed(ActionEvent e) { PuzzleTile pt = (PuzzleTile) e.getSource(); } /** * @return size of board */ public int getSize() { return mySize; } /** * @return the PuzzleTileFactory associated with the app */ public PuzzleTileFactory getFactory() { return myFactory; } public static void main(String args[]) { String filename; if (args.length == 1) { filename = "jimmy.gif"; } int size = 4; PuzzleTileFactory ptf = new ImagePuzzleTileFactory(filename,size); Puzzle app = new PuzzleApp(size,ptf); /* * we should construct a GUI thats separate from the application */ } private int mySize; private PuzzlePiece[][] myPieces; private PuzzleGui myGui; private PuzzleTileFactory myFactory; } /** * encapsulate a puzzle piece from the Application's perspective * this is mostly a labeled object with a PuzzleTile */ class PuzzlePiece { /** * @param gui the Interface to which this piece belongs * @param label the label associated with this piece * both in app and in gui */ public PuzzlePiece(PuzzleGui gui, String label) { myLabel = label; myTile = gui.makeTile(label); } /** * @param label is the string associated with this piece */ public void setLabel(String label) { myLabel = label; myTile.setLabel(label); } /** * @return the label associated with this piece */ public String getLabel() { return myLabel; } /** * @return the PuzzleTile associated with this piece */ public PuzzleTile getTile() { return myTile; } /** * @return a string-ized form of the puzzle piece */ public String toString() { return myLabel; } private String myLabel; private PuzzleTile myTile; }