From d613c81408dbd5eea60c17dfe34f7247365e89dc Mon Sep 17 00:00:00 2001 From: 3009594 Date: Sun, 29 Sep 2024 21:03:51 +0200 Subject: [PATCH] ChatApp --- .../Meine_GUI_Chat/ChatFenster.java | 33 +++++++ .../Meine_GUI_Chat/ChatManager.java | 27 ++++++ .../Meine_GUI_Chat/Chat_Fenster.java | 87 +++++++++++++++++++ .../Meine_GUI_Chat/Controller.java | 63 -------------- .../GUIAnwendungen/Meine_GUI_Chat/Main.java | 20 +++++ .../GUIAnwendungen/Meine_GUI_Chat/Modell.java | 54 ------------ .../GUIAnwendungen/Meine_GUI_Chat/Test.java | 13 --- .../GUIAnwendungen/Meine_GUI_Chat/User.java | 42 +++++++++ .../GUIAnwendungen/Meine_GUI_Chat/View.java | 70 --------------- .../Meine_GUI_Chat/View_Hauptfenster.java | 36 -------- .../src/LinkedList/Doubly/Test.java | 4 +- .../src/LinkedList/Generic/ElementenList.java | 15 +++- 12 files changed, 222 insertions(+), 242 deletions(-) create mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatFenster.java create mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatManager.java create mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Chat_Fenster.java delete mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Controller.java create mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Main.java delete mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Modell.java delete mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Test.java create mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/User.java delete mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View.java delete mode 100644 Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View_Hauptfenster.java diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatFenster.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatFenster.java new file mode 100644 index 0000000..410f47c --- /dev/null +++ b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatFenster.java @@ -0,0 +1,33 @@ +package GUIAnwendungen.Meine_GUI_Chat; + +public class ChatFenster { + + private User user; + private Chat_Fenster chat; + + ChatFenster(User user) { + this.user = user; + chat = new Chat_Fenster(); + zeigeName(); + } + + public void zeigeName() { + chat.zeigeName(user.getName()); + } + + public User getUser() { + return user; + } + + public Chat_Fenster getChat() { + return chat; + } + + public void empfangeNachricht(String nachricht) { + chat.sendText(nachricht); + } + + public void sendeNachricht(String nachricht) { + chat.sendText(user.getName() + ": " + nachricht); + } +} diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatManager.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatManager.java new file mode 100644 index 0000000..cb8bc66 --- /dev/null +++ b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/ChatManager.java @@ -0,0 +1,27 @@ +package GUIAnwendungen.Meine_GUI_Chat; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ChatManager implements ActionListener { + + private ChatFenster sender; + private ChatFenster receiver; + + ChatManager(ChatFenster sender, ChatFenster receiver) { + this.sender = sender; + this.receiver = receiver; + sender.getChat().getSendeNachricht().addActionListener(this); + receiver.getChat().getSendeNachricht().addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + String nachricht = sender.getChat().getEingabeNachricht().getText(); + if (!nachricht.isEmpty()) { + sender.sendeNachricht(nachricht); + receiver.empfangeNachricht(sender.getUser().getName() + ": " + nachricht); + sender.getChat().getEingabeNachricht().setText(""); + } + } +} \ No newline at end of file diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Chat_Fenster.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Chat_Fenster.java new file mode 100644 index 0000000..428c20a --- /dev/null +++ b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Chat_Fenster.java @@ -0,0 +1,87 @@ +package GUIAnwendungen.Meine_GUI_Chat; + +import java.awt.EventQueue; +import java.util.Scanner; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import java.awt.Color; +import javax.swing.JList; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JButton; +import java.awt.Font; +import javax.swing.JLabel; + +public class Chat_Fenster extends JFrame { + + JPanel contentPane; + JTextField eingabeNachricht; + JTextArea nachrichtAnzeigen; + JButton sendeNachricht; + private JPanel panel; + JLabel userName; + + public Chat_Fenster() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 460, 665); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + + setContentPane(contentPane); + contentPane.setLayout(null); + + nachrichtAnzeigen = new JTextArea(); + nachrichtAnzeigen.setLineWrap(true); + nachrichtAnzeigen.setFont(new Font("Tahoma", Font.BOLD, 13)); + nachrichtAnzeigen.setForeground(new Color(0, 128, 255)); + nachrichtAnzeigen.setEnabled(false); + nachrichtAnzeigen.setBounds(10, 11, 311, 516); + contentPane.add(nachrichtAnzeigen); + + eingabeNachricht = new JTextField(); + eingabeNachricht.setBounds(10, 538, 227, 31); + contentPane.add(eingabeNachricht); + eingabeNachricht.setColumns(10); + + sendeNachricht = new JButton("sendeNachricht"); + sendeNachricht.setBounds(247, 542, 135, 27); + contentPane.add(sendeNachricht); + + panel = new JPanel(); + panel.setBackground(new Color(0, 128, 255)); + panel.setBounds(331, 11, 103, 168); + contentPane.add(panel); + panel.setLayout(null); + + userName = new JLabel("New label"); + userName.setBounds(10, 11, 83, 36); + panel.add(userName); + + this.setVisible(true); + + } + + public void sendText(String nachricht) { + nachrichtAnzeigen.append(nachricht); + nachrichtAnzeigen.append("\n"); + } + + public void zeigeName(String name) { + userName.setText(name); + } + + public JTextField getEingabeNachricht() { + return eingabeNachricht; + } + + public JButton getSendeNachricht() { + return sendeNachricht; + } + + + + +} diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Controller.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Controller.java deleted file mode 100644 index 1a48a3f..0000000 --- a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Controller.java +++ /dev/null @@ -1,63 +0,0 @@ -package GUIAnwendungen.Meine_GUI_Chat; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -public class Controller { - - private Modell user1; - private View view; - private View_Hauptfenster h1 = new View_Hauptfenster(); - private String name; - private String password; - - Controller(Modell user, View view){ - this.user1 = user; - this.view = view; - } - - public boolean logIn() { - view.getLogIn().addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - name = view.getNameEingabe(); - password = view.getPasswordEingabe(); - user1 = new Modell(name,password); - view.zeigeUserInfos(); - view.schließeLoginFenster(); - zeigeHauptfenster(); - } - }); - return true; - } - - - public void zeigeHauptfenster() { - h1.zeigeBegrüße(user1.getName()); - - h1.setVisible(true); - } - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public Modell getUser1() { - return user1; - } - - - -} diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Main.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Main.java new file mode 100644 index 0000000..a3b592d --- /dev/null +++ b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Main.java @@ -0,0 +1,20 @@ +package GUIAnwendungen.Meine_GUI_Chat; + +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + + User obai = new User("obai Albek"); + ChatFenster obai_caht = new ChatFenster(obai); + + User omar = new User("Omar Albek"); + ChatFenster omar_chat = new ChatFenster(omar); + + ChatManager test = new ChatManager(obai_caht, omar_chat); + + + } + +} diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Modell.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Modell.java deleted file mode 100644 index d9ec80c..0000000 --- a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Modell.java +++ /dev/null @@ -1,54 +0,0 @@ -package GUIAnwendungen.Meine_GUI_Chat; - -public class Modell { - - private String name; - private int kontostand; - private int id; - private String password; - private static int ID = 100; - - public Modell() {} - public Modell(String name, String password) { - this.name = name; - this.kontostand = 0; - this.password = password; - this.id = ++ID; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - - - public int getKontostand() { - return kontostand; - } - public void setKontostand(int kontostand) { - this.kontostand = kontostand; - } - //set ID ist nicht erlaubt - public int getId() { - return id; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - @Override - public String toString() { - return "[name=" + name + ", Kontostand=" + kontostand + ", id=" + id + ", password=" + password + "]"; - } -} - - diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Test.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Test.java deleted file mode 100644 index 9f45cc4..0000000 --- a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/Test.java +++ /dev/null @@ -1,13 +0,0 @@ -package GUIAnwendungen.Meine_GUI_Chat; - -public class Test { - - public static void main(String[] args) { - View user1View = new View(); - Modell user1 = new Modell(); - - Controller controller = new Controller(user1,user1View); - controller.logIn(); - } - -} diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/User.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/User.java new file mode 100644 index 0000000..0278f95 --- /dev/null +++ b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/User.java @@ -0,0 +1,42 @@ +package GUIAnwendungen.Meine_GUI_Chat; + +import java.util.ArrayList; + +public class User { + private String name; + + private int id; + private String nachricht; + private static int ID = 100; + private ArrayList nachrichten; + + public User(String name) { + super(); + this.name = name; + this.id = ID++; + nachrichten = new ArrayList<>(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + public int getId() { + return id; + } + + public String getNachricht() { + return nachricht; + } + + public void setNachricht(String nachricht) { + this.nachricht = nachricht; + } + + +} diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View.java deleted file mode 100644 index 74aace1..0000000 --- a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View.java +++ /dev/null @@ -1,70 +0,0 @@ -package GUIAnwendungen.Meine_GUI_Chat; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPasswordField; -import javax.swing.JTextField; - -public class View extends JFrame { - - private JLabel title = new JLabel("Log in: "); - - private JLabel userName = new JLabel("Name: "); - private JTextField nameEingabe = new JTextField(); - private JLabel password = new JLabel("Password: "); - private JPasswordField passwordEingabe = new JPasswordField(); - private JButton logIn = new JButton("Log in"); - //(int x, int y, int width, int height) - - public View() { - this.setTitle("Log in"); - this.setVisible(true); - this.setSize(900, 650); - this.setLayout(null); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - - title.setBounds(10,20,120,20); - userName.setBounds(10,50,100,20); - nameEingabe.setBounds(140,50,140,20); - - password.setBounds(10,80,100,20); - passwordEingabe.setBounds(140,80,140,20); - logIn.setBounds(10,110,100,20); - - - this.add(title); - this.add(userName); - this.add(nameEingabe); - this.add(password); - this.add(passwordEingabe); - this.add(logIn); - - } - - public void zeigeUserInfos() { - JOptionPane.showMessageDialog(null, "Deine Log in war erfolgreich", "Log in Erfolgreich", JOptionPane.INFORMATION_MESSAGE); - } - - public String getNameEingabe() { - return nameEingabe.getText(); - } - - - public String getPasswordEingabe() { - return new String(passwordEingabe.getPassword()); - } - - public JButton getLogIn() { - return logIn; - } - - public void schließeLoginFenster() { - this.dispose(); // Schließt das aktuelle Fenster - } -} diff --git a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View_Hauptfenster.java b/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View_Hauptfenster.java deleted file mode 100644 index 875e508..0000000 --- a/Programmierung2/src/GUIAnwendungen/Meine_GUI_Chat/View_Hauptfenster.java +++ /dev/null @@ -1,36 +0,0 @@ -package GUIAnwendungen.Meine_GUI_Chat; - -import java.awt.Color; - -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; - -public class View_Hauptfenster extends JFrame{ - private JPanel panel = new JPanel(); - private JLabel begrüsse = new JLabel(); - - public View_Hauptfenster() { - panel.setBackground(Color.gray); - panel.setBounds(10, 10, 300, 300); - begrüsse.setBounds(10,10,100,30); - panel.add(begrüsse); - - this.setTitle("Das Hauptfenster"); - this.setVisible(false); - this.setLayout(null); - this.setSize(700, 700); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - this.add(panel); - - } - - public void zeigeBegrüße(String name) { - begrüsse.setText("Willkommen " + name); - } - - public static void main(String[]args) { - View_Hauptfenster test = new View_Hauptfenster(); - } - -} diff --git a/Programmierung2/src/LinkedList/Doubly/Test.java b/Programmierung2/src/LinkedList/Doubly/Test.java index fc8c9f2..49c002b 100644 --- a/Programmierung2/src/LinkedList/Doubly/Test.java +++ b/Programmierung2/src/LinkedList/Doubly/Test.java @@ -16,9 +16,7 @@ class Test { @org.junit.jupiter.api.Test void testaddLast() { - Node temp = list.addLast(12); - temp = list.addLast(112); - assertEquals(112,11); + } } diff --git a/Programmierung2/src/LinkedList/Generic/ElementenList.java b/Programmierung2/src/LinkedList/Generic/ElementenList.java index 86c9c4d..acb5313 100644 --- a/Programmierung2/src/LinkedList/Generic/ElementenList.java +++ b/Programmierung2/src/LinkedList/Generic/ElementenList.java @@ -1,12 +1,21 @@ package LinkedList.Generic; -public class ElementenList { - Node head; +public class ElementenList { + Node head; - public void addInt(T value) { + public void addInt(T value) { Node newNode = new Node<>(); newNode.value = value; + + head = newNode; + } + + + public static void main(String[] args) { + ElementenList test = new ElementenList<>(); + + }