master
3009594 2024-09-29 21:03:51 +02:00
parent 9d1f589804
commit d613c81408
12 changed files with 222 additions and 242 deletions

View File

@ -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);
}
}

View File

@ -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("");
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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 + "]";
}
}

View File

@ -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();
}
}

View File

@ -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<String> 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;
}
}

View File

@ -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
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -1,12 +1,21 @@
package LinkedList.Generic;
public class ElementenList {
Node<?> head;
public class ElementenList<T> {
Node<T> head;
public <T> void addInt(T value) {
public void addInt(T value) {
Node<T> newNode = new Node<>();
newNode.value = value;
head = newNode;
}
public static void main(String[] args) {
ElementenList<String> test = new ElementenList<>();
}