Write your choice of one of three GUI games that can run as either a windowed application or as an applet.
Text: Java Tutorial: Swing
Your options include:
Construct a GUI for your game. It should contain at least a grid of buttons. These buttons can start blank to show they are "empty" squares. When the player clicks on one, it should change appropriately. (TicTacToe: Change to an X or O; Concentration: Reveal the underlying word/image; Minesweeper: Reveal the underlying bomb or number.) You should disable clicked button (as appropriate) to prevent the player from changing a button that already shows a move.
The game must end on the appropriate conditions. (TicTacToe: either someone wins with 3 of the same characters in a row or there are no more empty squares; Concentration: All matching pairs have been uncovered; Minesweeper: The user clicks a mine or uncovers all non-mine squares.) You should report the final game outcome to the user. Once the user has had a chance to read that message, you can start a new game or provide some means (such as a Replay or Reset button) for the user to do so.
These are only the basic requirements. You are encouraged to go beyond this. A few ideas include:
You can earn up to +15 points for particularly nice GUI improvements and options. You can also earn up to another 15 additional points depending on the complexity of your game or its AI:
You may write additional classes as needed, but your main executable/JApplet class should be
Your main class should also be a JApplet that runs embedded in a webpage. (It is possible for applets to popup a JFrame window, but don't do that. Instead, keep the applet content in the webpage itself.) Create the necessary HTML page. This page should have additional info too, such as a description of the game and a link to the associated documentation.
Make sure all of your methods are documented. In the overview documentation for your main class, describe/list any extra credit enhancements you made or any existing bugs or problems. Also, you must include the full URL in the documentation to a working version of your applet on www2.hawaii.edu.
Run the javadoc tool to extract your documentation into HTML pages. Upload all of these pages to www2.hawaii.edu, preferably in a single subdirectory. As mentioned, your applet page should contain a link to the index.html page of this extracted documentation.
These are just examples to show you the basic idea of what you would need.
I had to resize the window to make it look like this. I used the setEnabled method on the buttons to disable buttons that should not be clickable. I disable all the buttons as soon as someone wins so the user can't continue the game. Also at the end of the game, I enable the Play Again button. Clicking that returns the game to the initial state shown on the left.
A winning game
(pop-up results not shown)
A losing game
(pop-up results not shown)
Thanks to Anthony Christe for the demo implementation.
You will upload your source code to Tamarin, but it will only check that everything compiles. Your TA will then grade your submission manually.
Create a .jar including all of your .java files and your applet's .html file. The class documentation of your main class should include the complete URL of your working applet and extracted documentation. You should not include the extracted documentation pages in jar. Upload your
UsernameA07.jar file to Tamarin.
Remember to follow the course coding standards on all assignments.
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "myimage.png" "read")
This suggests that this is a unix file permissions problem that can be fixed with the
chmod command. This is not actually the case.
What's actually happening here is that the .class file has been downloaded from the server and is running in your browser on your local (client) machine. Your applet is then trying to access some file--myimage.png, in this case. But your applet is looking for that file in the same directory as itself... but, since it's now running on the user's machine, it's trying to find some file in its local directory there. But, due to the Java security sandbox, an applet does not have permission to read files on the user's machine! Hence, the exception.
This is not a problem when you run the applet directly from your local machine because it is able to access files in the same or child directories of where it came from, and both the applet and the image are then on the same computer.
The recommended fix for this is to bundle the images with your .class file in a jar file. This can be an executable jar or not. You can then use the getResource() method, which is in the class Class
//assuming myimage.png is in the root of the jar file with all your .class files ImageIcon icon = new ImageIcon(this.getClass().getResource("myimage.png"));
You will need to specify in your HTML file that your applet class is now in a jar, like so:
<applet code="UsernameA07.class" archive="UsernameA07.jar" width="200" height="180">
Here is the current list of the known causes:
init()is not a static method. That means the JVM needs to build an instance of your JApplet-extending class before it can call
init()and start your applet running. However, since the JVM won't know about any parameters your constructor requires, you need a constructor that takes no parameters.
This behavior will indirectly call System.exit, but an applet is not allowed to kill the JVM like that due to the applet's sandbox security restrictions. You could just comment out this line, but then your JFrame won't work properly when you run the program as an application. Besides, when run as an applet, you shouldn't create a JFrame at all.
The design solution is to create the JFrame in your main method, not in your constructor. Your constructor should only create a top-level JPanel. (See the NumberPad demo code above for example main and init methods.)
If your problem is not one of those listed here, look for other reasons why your constructor or init() method might generate an exception.