Compare commits

...

2 commits

View file

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