Browse Source

Zwischenstand

Jens
Jens Schuhmann 1 year ago
parent
commit
109123a241

+ 1
- 1
src/ChatProgramm/controller/CommandController.java View File

@@ -42,7 +42,7 @@ public class CommandController implements ActionListener{
public void registerCommands(){
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view));
invoker.addCommand(view.getTfNachricht(), new CommandSend());
invoker.addCommand(view.getTfNachricht(), new CommandSend(view));
}

/**

src/ChatProgramm/model/Nachricht.java → src/ChatProgramm/controller/Nachricht.java View File

@@ -3,13 +3,13 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/

package ChatProgramm.model;
package ChatProgramm.controller;

/**
*
* @author ahren
*/
class Nachricht
public class Nachricht
{
private String nachricht;
//private int id;

src/ChatProgramm/model/ReceiveAdapter.java → src/ChatProgramm/controller/ReceiveAdapter.java View File

@@ -2,7 +2,7 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ChatProgramm.model;
package ChatProgramm.controller;

import ChatProgramm.view.ChatView;
import java.util.concurrent.Flow;

+ 22
- 2
src/ChatProgramm/controller/commands/CommandSend.java View File

@@ -5,20 +5,40 @@

package ChatProgramm.controller.commands;

import ChatProgramm.controller.Nachricht;
import ChatProgramm.model.Client;
import ChatProgramm.model.Server;
import ChatProgramm.model.Transmitter;
import ChatProgramm.util.OhmLogger;
import ChatProgramm.view.ChatView;
import java.util.logging.Logger;
import javax.swing.JTextField;

/**
*
* @author ahren
*/
public class CommandSend implements CommandInterface
{
public CommandSend()
private static Logger lg = OhmLogger.getLogger();
private ChatView view;
private JTextField eingabeFeld;
public Server server;
public Client client;
public CommandSend(ChatView view)
{
this.view = view;
this.eingabeFeld = view.getTfNachricht();
}

@Override
public void execute()
{
//Transmitter.send(new Nachricht(eingabeFeld.getText()));
lg.info("Sende Nachricht");
}

@Override

+ 1
- 11
src/ChatProgramm/model/Client.java View File

@@ -4,6 +4,7 @@
*/
package ChatProgramm.model;

import ChatProgramm.controller.Nachricht;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -25,12 +26,6 @@ public class Client extends Transmitter {

private static Logger lg = Logger.getLogger("netz");

private Socket socket;
private BufferedReader reader;
private PrintWriter writer;

private static final int PORT = 35000; //lt. iana port > 2¹⁵
private static final String IP = "127.0.0.1";

public Client() throws IOException {
connect();
@@ -73,10 +68,5 @@ public class Client extends Transmitter {
}
}

@Override
public void onNext(Nachricht item) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}

+ 2
- 0
src/ChatProgramm/model/Server.java View File

@@ -30,6 +30,7 @@ public class Server extends Transmitter {
private static Logger lg = Logger.getLogger("netz");


@Override
public void connect() throws IOException {
try {
ServerSocket sSocket = new ServerSocket(PORT);
@@ -47,6 +48,7 @@ public class Server extends Transmitter {


public Server() throws IOException {
super();
connect();
initIO();


+ 35
- 5
src/ChatProgramm/model/Transmitter.java View File

@@ -4,6 +4,7 @@
*/
package ChatProgramm.model;

import ChatProgramm.controller.Nachricht;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -26,7 +27,7 @@ import java.util.logging.Logger;
*/
public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {

static final int timeout = 60000;
static final int timeout = 10000;
protected static final int PORT = 35000;
protected static final String IP = "127.0.0.1";

@@ -37,13 +38,19 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
protected PrintWriter writer;

private SubmissionPublisher<Nachricht> textPublisher;
private Thread thd;
private boolean laufend;

public Transmitter() {
socket = new Socket();
}

public abstract void connect() throws IOException;

public void addWertSubscription(Subscriber<Nachricht> subscriber) {
textPublisher.subscribe(subscriber);
}

public void initIO() {
try {
lg.info("Initialisiere reader und writer");
@@ -66,19 +73,42 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
}
}

public void addWertSubscription(Subscriber<Nachricht> subscriber) {
textPublisher.subscribe(subscriber);
public void send(Nachricht nachricht) {
lg.info("Nachricht wird gesendet");
writer.println(nachricht.getNachricht());
writer.flush();

lg.info("Nachricht wird angezeigt");
textPublisher.submit(nachricht);
}

// public void startServer() {
// laufend = true;
// if (thd == null) {
// thd = new Thread(this);
// thd.start();
// }
//
// synchronized (thd) {
// thd.notify();
// }
//
// }

@Override
public void run() {
try {
Nachricht nachricht = new Nachricht(reader.readLine());
textPublisher.submit(nachricht);
} catch (IOException ex) {
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
}
}

@Override
public void onSubscribe(Flow.Subscription subscription) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void onError(Throwable throwable) {

Loading…
Cancel
Save