summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300>2006-03-07 00:13:10 +0000
committerjada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300>2006-03-07 00:13:10 +0000
commit27d67dac08b9afab2efe77af7d010184373c0bc6 (patch)
tree72f4561973002499e7b859f2c62f922566f7072a
parentfc9db7434715e36205ce2e16c3645b9db30f2277 (diff)
Fixed a bug and disable write to scores file in FourByFour example.
-rw-r--r--src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java99
1 files changed, 36 insertions, 63 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java
index 573e27e..c1faf63 100644
--- a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java
+++ b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java
@@ -65,6 +65,9 @@ import org.jdesktop.j3d.examples.Resources;
*/
public class FourByFour extends Applet implements ActionListener {
+ // To write scores to scores file
+ private static final boolean writeScoresFile = false;
+
String host; // Host from which this applet came from
int port; // Port number for writing high scores
Image backbuffer2D; // Backbuffer image used for 2D double buffering
@@ -107,7 +110,6 @@ public class FourByFour extends Applet implements ActionListener {
Button high_return_button; // Return button for high scores panel
CheckboxGroup group; // CheckboxGroup object for skill level panel
InputStream inStream; // Input stream for reading instructions and high scores
- OutputStream outStream; // Output stream for writing high scores
static boolean appletFlag = true; // Applet flag
boolean winner_flag = false; // Winner flag
byte text[]; // Temporary storage area for reading instructions file
@@ -632,64 +634,35 @@ public class FourByFour extends Applet implements ActionListener {
scoresString += "\n";
}
- if (appletFlag) {
- // Use this section of code when writing the high
- // scores file back to a server. Requires the use
- // of a deamon on the server to receive the socket
- // connection.
- //
- // Create the output stream.
- // try {
- // Socket socket = new Socket(host, port);
- // outStream = new BufferedOutputStream
- // (socket.getOutputStream(), 8192);
- // }
- // catch(IOException ioe) {
- // System.out.println("Error: " + ioe.toString());
- // }
- // System.out.println("Output stream opened");
- //
- // Write the scores to the file back on the server.
- // outText = scoresString.getBytes();
- // try {
- // outStream.write(outText);
- // outStream.flush();
- // outStream.close();
- // outStream = null;
- // }
- // catch (IOException ioe) {
- // System.out.println("Error: " + ioe.toString());
- // }
- // System.out.println("Output stream written");
-
- try {
- OutputStreamWriter outFile =
- new OutputStreamWriter(new FileOutputStream("scores.txt"));
- outFile.write(scoresString);
- outFile.flush();
- outFile.close();
- outFile = null;
- }
- catch (IOException ioe) {
- System.out.println("Error: " + ioe.toString());
- }
- catch (Exception e) {
- System.out.println("Error: " + e.toString());
- }
- }
- else {
-
- try {
- OutputStreamWriter outFile =
- new OutputStreamWriter(new FileOutputStream("scores.txt"));
- outFile.write(scoresString);
- outFile.flush();
- outFile.close();
- outFile = null;
- }
- catch (IOException ioe) {
- System.out.println("Error: " + ioe.toString());
- }
+ if(writeScoresFile) {
+ if (appletFlag) {
+ try {
+ OutputStreamWriter outFile =
+ new OutputStreamWriter(new FileOutputStream("scores.txt"));
+ outFile.write(scoresString);
+ outFile.flush();
+ outFile.close();
+ outFile = null;
+ } catch (IOException ioe) {
+ System.out.println("Error: " + ioe.toString());
+ } catch (Exception e) {
+ System.out.println("Error: " + e.toString());
+ }
+
+ } else {
+
+ try {
+
+ OutputStreamWriter outFile =
+ new OutputStreamWriter(new FileOutputStream("scores.txt"));
+ outFile.write(scoresString);
+ outFile.flush();
+ outFile.close();
+ outFile = null;
+ } catch (IOException ioe) {
+ System.out.println("Error: " + ioe.toString());
+ }
+ }
}
}
winner_panel.setVisible(false);
@@ -738,8 +711,8 @@ public class FourByFour extends Applet implements ActionListener {
// Read the high scores file.
if (appletFlag) {
try {
- inStream = new BufferedInputStream
- (new URL(getCodeBase(), "scores.txt").openStream(), 8192);
+ URL scoreURL = Resources.getResource("four_by_four/scores.txt");
+ inStream = new BufferedInputStream(scoreURL.openStream(), 8192);
Reader read = new BufferedReader(new InputStreamReader(inStream));
StreamTokenizer st = new StreamTokenizer(read);
st.whitespaceChars(32,44);
@@ -771,8 +744,8 @@ public class FourByFour extends Applet implements ActionListener {
}
else {
try {
- inStream = new BufferedInputStream
- (new FileInputStream("scores.txt"));
+ URL scoreURL = Resources.getResource("four_by_four/scores.txt");
+ inStream = new BufferedInputStream(scoreURL.openStream(), 8192);
Reader read = new BufferedReader(new InputStreamReader(inStream));
StreamTokenizer st = new StreamTokenizer(read);
st.whitespaceChars(32,44);