Userobjekt erstellt, kommentiert. UMLClient erstellt
This commit is contained in:
parent
9591946e9b
commit
09c4af5308
3 changed files with 99 additions and 20 deletions
|
@ -63,6 +63,7 @@ public class Client1 extends JFrame {
|
|||
private static int anzahlVersuche = 0; //Ist gleich die AN
|
||||
private static int anzahlRekursionen = 0;
|
||||
private static Message temp = new Message("leer", "leer");
|
||||
private static User user;
|
||||
|
||||
/**
|
||||
* In der main Methode wird das GUI erstellt und die start() Methode
|
||||
|
@ -115,6 +116,37 @@ public class Client1 extends JFrame {
|
|||
txtUsername.setBounds(20, 11, 86, 20);
|
||||
contentPane.add(txtUsername);
|
||||
txtUsername.setColumns(10);
|
||||
|
||||
|
||||
/**
|
||||
* Der Start Button sorgt sorgt dafür, dass der Username festgesetzt
|
||||
* 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() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
/**
|
||||
* Hier wird ein User-Objekt hergestellt
|
||||
*/
|
||||
|
||||
String name = txtUsername.getText();
|
||||
String nachricht = txtMessage.getText();
|
||||
|
||||
user = new User(name, nachricht);
|
||||
|
||||
txtUsername.setEditable(false);
|
||||
txtUsername.setEnabled(false);
|
||||
verbunden = true;
|
||||
|
||||
}
|
||||
});
|
||||
btnStart.setBounds(116, 10, 89, 23);
|
||||
contentPane.add(btnStart);
|
||||
|
||||
|
||||
/**
|
||||
* Der Button "Send" nimmt die aktuelle Nachricht, welche im Textfeld
|
||||
|
@ -131,12 +163,13 @@ public class Client1 extends JFrame {
|
|||
if (verbunden) {
|
||||
|
||||
String themessage = txtMessage.getText();
|
||||
String theusername = txtUsername.getText();
|
||||
//String theusername = user.getUsername();
|
||||
|
||||
tosend = new Message(theusername, themessage);
|
||||
tosend = new Message(user.getUsername(), themessage);
|
||||
i = 1;
|
||||
|
||||
temp = new Message(theusername, themessage);
|
||||
temp = new Message(user.getUsername(), themessage);
|
||||
|
||||
System.out.println("Button pressed");
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
@ -149,12 +182,16 @@ public class Client1 extends JFrame {
|
|||
} catch (Exception k) {
|
||||
print("KEINE VERBINDUNG");
|
||||
}
|
||||
|
||||
user.setMessage(themessage);
|
||||
|
||||
if (temp.getMessage().equals("exit")) {
|
||||
System.exit(0);
|
||||
}
|
||||
txtMessage.setText("");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -174,24 +211,7 @@ public class Client1 extends JFrame {
|
|||
textArea.setBounds(20, 42, 323, 176);
|
||||
contentPane.add(textArea);
|
||||
|
||||
/**
|
||||
* Der Start Button sorgt sorgt dafür, dass der Username festgesetzt
|
||||
* 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() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
|
||||
txtUsername.setEditable(false);
|
||||
txtUsername.setEnabled(false);
|
||||
verbunden = true;
|
||||
|
||||
}
|
||||
});
|
||||
btnStart.setBounds(116, 10, 89, 23);
|
||||
contentPane.add(btnStart);
|
||||
|
||||
}
|
||||
|
||||
|
|
59
src/client/User.java
Normal file
59
src/client/User.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (C) 2021 berdan
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package client;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @author berdan
|
||||
*/
|
||||
|
||||
|
||||
public class User {
|
||||
|
||||
private String username;
|
||||
private String currentmessage;
|
||||
|
||||
/**
|
||||
* Der Konstrukter des User-Objektes
|
||||
* @param username1 Der Nutzername
|
||||
* @param message1 Die Nachricht
|
||||
*/
|
||||
public User(String username1, String message1){
|
||||
this.username = username1;
|
||||
this.currentmessage = message1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param newMessage Die neue Nachricht
|
||||
*/
|
||||
public void setMessage(String newMessage){
|
||||
this.currentmessage = newMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Die get-Methode für den Username
|
||||
* @return Der Nutzernamen
|
||||
*/
|
||||
|
||||
public String getUsername(){
|
||||
return this.username;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
BIN
src/documetation/Bild.jpg
Normal file
BIN
src/documetation/Bild.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
Loading…
Reference in a new issue