ajout de popup d'erreurs lors d'une tentative de connection avec un nom invalide

This commit is contained in:
Louis Farina 2021-01-07 18:07:29 +01:00
parent 88f3760164
commit eea9f2b769
2 changed files with 9 additions and 2 deletions

View file

@ -52,6 +52,13 @@ public class ClientWindow implements ActionListener {
JOptionPane.PLAIN_MESSAGE); JOptionPane.PLAIN_MESSAGE);
connected = network.connect(username); connected = network.connect(username);
if(!connected)
{
if(username.equals(""))
JOptionPane.showMessageDialog(chatWindow, "Please enter a username", "Error", JOptionPane.ERROR_MESSAGE);
else if (username != null)
JOptionPane.showMessageDialog(chatWindow, "This username is already taken", "Error", JOptionPane.ERROR_MESSAGE);
}
} }
if(username != null) if(username != null)

View file

@ -267,13 +267,13 @@ public class NetworkClient {
System.out.println(userList.get(i).getName() + " : " + userList.get(i).getAddress()); System.out.println(userList.get(i).getName() + " : " + userList.get(i).getAddress());
known_users.add(userList.get(i)); known_users.add(userList.get(i));
} }
known_users.add(new User(username, "25.68.185.103")); known_users.add(new User(username, "25.67.234.235"));
connected = true; connected = true;
} }
} }
catch(SocketTimeoutException e) catch(SocketTimeoutException e)
{ {
known_users.add(new User(username, "25.68.185.103")); known_users.add(new User(username, "25.67.234.235"));
System.out.println("Reply timed out"); System.out.println("Reply timed out");
connected = true; connected = true;
} }