J
justin
I am writing a Hi-Score GUI whereby it is suppose to store an array of
10 players when the input name comes up. But I am having problems
doing it was wondering if anyone can help thanks.Below is a snippet of
my codes when doign ObjectStreams. BTW when trying out in terms
writing not as an Object but as a textFile this works so yeah the only
problem was it wouldn't append so if anyone could show me how as well
it would be much appreciated. Thanks
void okButton_actionPerformed(ActionEvent e) throws (<-------- this
is in my PlayerInputGUI which is the GUI whereby players enter their
names onto a textField)
FileNotFoundException,IOException {
File scoreFile = new File("Scores.dat");
FileOutputStream outFileStream = new FileOutputStream(scoreFile);
ObjectOutputStream outObjectStream = new
ObjectOutputStream(outFileStream);
PlayerDetails players[]= null;
for(int i=0;i<10;i++){
players = new PlayerDetails(inputField.getText());
outObjectStream.writeObject(players);
}
outObjectStream.close();
this.hide();
}
void highScore_actionPerformed(ActionEvent e) throws
FileNotFoundException, IOException,
ClassNotFoundException < ---- (THIS IS IN THE OTHER GUI THE MAIN
GAME GUI, this basically functions to display the scores on the
JOptionPane){
File inFile = new File("Scores.dat");
FileInputStream inFileStream = new FileInputStream(inFile);
ObjectInputStream inObjectStream = new
ObjectInputStream(inFileStream);
PlayerDetails players;
for (int i=0;i<10;i++){
players=(PlayerDetails)inObjectStream.readObject();
JOptionPane.showMessageDialog(null,"1 "+players.getName());
(WHILST MEDDLING AROUND I GOT AN ERROR stating that
"MovingTilesApp.java": getName(java.lang.String) in
sg_board.PlayerDetails cannot be applied to () at line 261, column 59
& I DON'T KNOW WHY)
inObjectStream.close();
}
}
AND LASTLY MY PlayerDetails Class
import java.io.*;
public class PlayerDetails implements Serializable{
private String name;
//public static void main(String[] args) {
public PlayerDetails( String n){
name = n;
}
public void setName(String n) {
name = n;
}
public void getName (String n){
name = n;
}
}
10 players when the input name comes up. But I am having problems
doing it was wondering if anyone can help thanks.Below is a snippet of
my codes when doign ObjectStreams. BTW when trying out in terms
writing not as an Object but as a textFile this works so yeah the only
problem was it wouldn't append so if anyone could show me how as well
it would be much appreciated. Thanks
void okButton_actionPerformed(ActionEvent e) throws (<-------- this
is in my PlayerInputGUI which is the GUI whereby players enter their
names onto a textField)
FileNotFoundException,IOException {
File scoreFile = new File("Scores.dat");
FileOutputStream outFileStream = new FileOutputStream(scoreFile);
ObjectOutputStream outObjectStream = new
ObjectOutputStream(outFileStream);
PlayerDetails players[]= null;
for(int i=0;i<10;i++){
players = new PlayerDetails(inputField.getText());
outObjectStream.writeObject(players);
}
outObjectStream.close();
this.hide();
}
void highScore_actionPerformed(ActionEvent e) throws
FileNotFoundException, IOException,
ClassNotFoundException < ---- (THIS IS IN THE OTHER GUI THE MAIN
GAME GUI, this basically functions to display the scores on the
JOptionPane){
File inFile = new File("Scores.dat");
FileInputStream inFileStream = new FileInputStream(inFile);
ObjectInputStream inObjectStream = new
ObjectInputStream(inFileStream);
PlayerDetails players;
for (int i=0;i<10;i++){
players=(PlayerDetails)inObjectStream.readObject();
JOptionPane.showMessageDialog(null,"1 "+players.getName());
(WHILST MEDDLING AROUND I GOT AN ERROR stating that
"MovingTilesApp.java": getName(java.lang.String) in
sg_board.PlayerDetails cannot be applied to () at line 261, column 59
& I DON'T KNOW WHY)
inObjectStream.close();
}
}
AND LASTLY MY PlayerDetails Class
import java.io.*;
public class PlayerDetails implements Serializable{
private String name;
//public static void main(String[] args) {
public PlayerDetails( String n){
name = n;
}
public void setName(String n) {
name = n;
}
public void getName (String n){
name = n;
}
}