Click on Applet Screen to Activate and then S to Start
(please wait...it takes a while to load the cards...)
S - to start and re-start the same game
N - to start a whole new game
This looks best with Google Chrome or Firefox
Don't know how to play - check out: how to play FreeCell
On the TODO: list
- Allow user to start a whole new game - DONE
- Detect when the user gets stuck
- Let the user know if they are trying to move too many cards
- End of game fireworks (a la Windows version)
- Change card spacing if the number of cards on a line gets too long
- Display (loading...) message
- Convert to jar file to improve start performance - DONE
- Right mouse down exposes the entire card in tableau area - DONE
Problems and issues when moving applet into jar
===> I wanted to convert to jar file in order to improve the loading time. It was taking about around 30 seconds to a minute to load
all the images since 52 cards plus the main screen had to be loaded. The applet was working fine running from Eclipse but I found it
could not locate the images in the jar.
1. Replacing ImageIO.read(url)
Originally I used the following code to load the images:
URL url = new URL(codeBase, imagePath + String.valueOf(cardNum) + imageExtension);
img = ImageIO.read(url);
where
imagePath = "../resources/images"
The above works but was totally wrong to use. First the applet ran from the Eclipse output directory which was the default of /bin. I
should have readlly used "./images"
since Eclipse was moving all working subdirectories under /bin.
But that was not the solution to my problem I really needed to use:
img = ImageIO.read(getClass().getResourceAsStream(FreeCell.imagePath + String.valueOf(cardNum) + imageExtension));
the above makes the code location independent! This allows to run and execute successfully on my PC and from a web browser.
The html applet tag was:
APPLET ID="FREECELL" CODEBASE="." CODE="FreeCell.class" ARCHIVE="freecell.jar" WIDTH="740" HEIGHT="480"
2. Applet did not receive keypresses so it would not start
The file images were now correctly obtained from the jar file (note: I just used Eclipse "Export" function to create jar file) but
the applet did not get any of the keyboard key presses so it would not start! The applet recorded all mouse actions but did not get any
of the keystrokes. I found something on the Internet that I did not think would work but alas it did. I adding the following code:
last line in init(): setFocusable(true);
last line in start(): requestFocusInWindow();
3. Applet area blank until user clicked on it.
There was a lot of improvement but now it seems the applet window was BLANK until the user directly gave it the focus so I added
the following JavaScript (onLoad):
function giveAppletFocus() {
document.getElementById("FREECELL").requestFocus();
}
The above gives the applet direct focus after the page loads.
Now it works....if it does not. I have uploaded the lasted set of Eclipse project files.