diff --git a/src/client/Client1.java b/src/client/Client1.java index bfce9ee..fba7c0d 100644 --- a/src/client/Client1.java +++ b/src/client/Client1.java @@ -24,11 +24,12 @@ import java.awt.event.ActionEvent; * @version 0.1.3 * @author berdan */ + public class Client1 extends JFrame { - /* - Hier werden Objekte und Variablen deklariert, damit diese - in allen Methoden genutzt werden können. + /** + * Hier werden Objekte und Variablen deklariert, damit diese in allen + * Methoden genutzt werden können. */ private static JPanel contentPane; JTextField txtMessage; @@ -45,10 +46,13 @@ public class Client1 extends JFrame { public static int anzahlVersuche = 0; //Ist gleich die AN public static int anzahlRekursionen = 0; public static Message temp = new Message("leer", "leer"); - - /* - In der main Methode wird das GUI erstellt und die - start() Methode aufgerufen. + + /** + * In der main Methode wird das GUI erstellt und die start() Methode + * aufgerufen. + * + * @param args + * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { t1 = new Client1(); @@ -65,20 +69,16 @@ public class Client1 extends JFrame { try { start(); - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block + } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); } } - /* - In der Methode Client1() wird das GUI - und die Befehle die durch einen Click des - Button's ausgelöst werden festgelegt + /** + * In der Methode Client1() wird das GUI und die Befehle die durch einen + * Click des Button's ausgelöst werden festgelegt (Konstruktur) */ + public Client1() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); @@ -125,12 +125,10 @@ public class Client1 extends JFrame { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { - try { - oboust.writeObject(tosend); - oboust.flush(); - } catch (IOException e) { - e.printStackTrace(); - } + oboust.writeObject(tosend); + oboust.flush(); + } catch (IOException e) { + e.printStackTrace(); } catch (Exception k) { print("KEINE VERBINDUNG"); } @@ -138,9 +136,8 @@ public class Client1 extends JFrame { if (temp.getMessage().equals("exit")) { System.exit(0); } - txtMessage.setText(""); - + } } @@ -152,7 +149,6 @@ public class Client1 extends JFrame { /** * Hier wird die textArea, auf welcher der Text ausgegeben wird * initialisiert - * */ textArea = new JTextArea(currentText); textArea.setLineWrap(true); @@ -166,7 +162,6 @@ public class Client1 extends JFrame { * wird, wodurch er nicht veränderlich ist. Außerdem wird die globale * Variabel j von 0 auf 1 gestzt, wodurch die start-Methode weiß, dass * sie eine Verbindung aufbauen soll. - * */ JButton btnStart = new JButton("Start"); btnStart.addActionListener(new ActionListener() { @@ -186,6 +181,8 @@ public class Client1 extends JFrame { /** * In der Print-Methode wird der neue Text (also eine neue Nachricht) auf * die textArea abgebildet. + * + * @param neuerText */ public static void print(String neuerText) { currentText = neuerText + "\n" + currentText; @@ -204,6 +201,9 @@ public class Client1 extends JFrame { * * Es wird im Sekundentakt nach einer neuen Verbindung gesucht. * + * @throws IOException + * @throws ClassNotFoundException + * @throws InterruptedException */ public static void start() throws IOException, ClassNotFoundException, InterruptedException { @@ -221,12 +221,14 @@ public class Client1 extends JFrame { print("VERBINDUNG HERGESTELLT"); } catch (Exception KeineSocket) { print("SERVER ANTWORTET NICHT"); + try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } + anzahlRekursionen++; if (anzahlRekursionen == 10) { print("KEINE ANTWORT, CLIENT WIRD BEENDET"); @@ -254,8 +256,8 @@ public class Client1 extends JFrame { * Benutzer über das GUI sendet "exit" lautet. * */ + while (!temp.getMessage().equals("exit")) { - //System.out.println("WHILE"); try { //System.out.println("hile4"); System.out.println("Nachricht erhalten");