package mug13; /* * UserThread is a thread that processes user input * * * @author Brett McMillian * @author Louisa Poythress */ import java.net.*; import java.io.*; public class UserThread extends Thread { //*************** // Fields //*************** Client user; PrintWriter pen; BufferedReader keyboard; //*************** // Constructors //*************** public UserThread(Client c, PrintWriter p, BufferedReader br) { this.user = c; this.pen = p; this.keyboard = br; } //*************** // Methods //*************** public void run() { try { pen.print("Would you like to update your password [Y/N]?"); pen.flush(); String updatePassword = keyboard.readLine(); if ((updatePassword.equals("Y")) || (updatePassword.equals("y"))) { while (true) { pen.print("Enter password: "); pen.flush(); String password1 = keyboard.readLine(); pen.print("Enter password again: "); pen.flush(); String password2 = keyboard.readLine(); if (password1.equals(password2)) { user.setAccount(password1); break; } else pen.println("Passwords didn't match"); } } while (true) { //Perform method should go here, and these two functions should //be placed inside the perform method user.getInstructions(new Action("Bill","Kill","Chainsaw")); user.broadcast("Hi", new String[] { "mcmillia" }); user.getInstructions(new Action("Tom","Smile")); user.broadcast("Hi", new String[] { "mcmillia" }); //This allows the network time to process the methods between //the client and server try { this.sleep(2000); } catch (InterruptedException e) {} //Don't need this in the real user interface pen.print("Would you like to exit [Y/N]?"); pen.flush(); String exit = keyboard.readLine(); //You will need this however if ((exit.equals("Y")) || (exit.equals("y"))) { this.user.closeConnection(); break; } } } catch (UnknownHostException e) {} catch (IOException e) {} catch (ClassNotFoundException e) {} } }