Now i created a Client for the HOPP. i made a button which submits the guess to the server, but logically this doesnt output. What do you think seems to be the problem here.
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if(command.equals("Join Game")){
serverResponseArea.append("Sending join game request\n");
try{
clientHOPP.send(new Message(JOIN_REQUEST));
Message msg = (Message)clientHOPP.receive();
if(msg.getType() == JOIN_ACK){
serverResponseArea.append("Successfully joined game\n");
activeGame = true;
joinButton.setEnabled(false);
}
} catch (IOException e1) {
serverResponseArea.append("Communication Error: "+e1.getMessage());
} catch (ClassNotFoundException cnf) {
serverResponseArea.append(cnf.getMessage());
}
}
else if(command.equals("Submit Guess")){
String inString = guessField.getText().trim();
if(inString == null || inString.length() == 0){
serverResponseArea.append("Please enter a number \n");
}
int input = Integer.parseInt(inString);
serverResponseArea.append("Guess is: " + inString +"\n");
try{
clientHOPP.send(new Message(input));
/*Test*/serverResponseArea.append(input+" sent.\n");
guessField.setText("");
Message inMsg = (Message)clientHOPP.receive();
if(inMsg.getType()== GUESS_RESPONSE)
{
GuessResponse response = (GuessResponse)inMsg.getMessageContents();
if(response.getResponseType()==HIGHER)
serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): HIGHER!");
else if(response.getResponseType() == LOWER)
serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): LOWER!");
else if(response.getResponseType() == INVALID_NUMBER)
serverResponseArea.append("Invalid number. Please choose a number between 1 - 999");
else if(response.getResponseType() == WIN)
serverResponseArea.append("Congratulations. You Win in "+response.getGuessNumber()+" guesses");
else if(response.getResponseType() == LOSE)
serverResponseArea.append("Sorry, you lose");
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch(ClassNotFoundException cnf){
serverResponseArea.append(cnf.getMessage());
}
serverResponseArea.append(inString+"\n");
guessField.setText("");
}
}
}