Browse Source

InitIO klappt und wir landen in der senden Funktion

Jens
Jens Schuhmann 1 year ago
parent
commit
6642dc8179

+ 1
- 1
src/ChatProgramm/Start.java View File

GrafikView zeichenflaeche = view.getGvZeichenflaeche(); GrafikView zeichenflaeche = view.getGvZeichenflaeche();
zeichenflaeche.setModel(model); zeichenflaeche.setModel(model);
CommandController controller_commands = new CommandController(view);
CommandController controller_commands = new CommandController(view, model);
controller_commands.registerEvents(); controller_commands.registerEvents();
controller_commands.registerCommands(); controller_commands.registerCommands();

+ 5
- 2
src/ChatProgramm/controller/CommandController.java View File

import ChatProgramm.controller.commands.CommandConnect; import ChatProgramm.controller.commands.CommandConnect;
import ChatProgramm.controller.commands.CommandInvoker; import ChatProgramm.controller.commands.CommandInvoker;
import ChatProgramm.controller.commands.CommandSend; import ChatProgramm.controller.commands.CommandSend;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.view.ChatView; import ChatProgramm.view.ChatView;
import java.awt.Component; import java.awt.Component;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
public class CommandController implements ActionListener{ public class CommandController implements ActionListener{
private ChatView view; private ChatView view;
private GrafikModel model;
private CommandInvoker invoker; private CommandInvoker invoker;
public CommandController(ChatView view){
public CommandController(ChatView view, GrafikModel model){
this.view = view; this.view = view;
this.model = model;
this.invoker = new CommandInvoker(); this.invoker = new CommandInvoker();
} }
} }
public void registerCommands(){ public void registerCommands(){
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche());
CommandSend commandSend = new CommandSend(view.getGvZeichenflaeche(), model);
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend)); invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
//invoker.addCommand(view.getTfNachricht(), commandSend); //invoker.addCommand(view.getTfNachricht(), commandSend);
} }

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

{ {
this.view = view; this.view = view;
this.model = model; this.model = model;
commandSend = new CommandSend(view);
commandSend = new CommandSend(view, model);
} }
public void registerEvents() public void registerEvents()

+ 7
- 1
src/ChatProgramm/controller/commands/CommandSend.java View File

package ChatProgramm.controller.commands; package ChatProgramm.controller.commands;


import ChatProgramm.model.Client; import ChatProgramm.model.Client;
import ChatProgramm.model.Figur;
import ChatProgramm.model.GrafikModel;
import ChatProgramm.model.Server; import ChatProgramm.model.Server;
import ChatProgramm.model.TransmitterInterface; import ChatProgramm.model.TransmitterInterface;
import ChatProgramm.util.OhmLogger; import ChatProgramm.util.OhmLogger;
private JTextField eingabeFeld; private JTextField eingabeFeld;
private String nachricht; private String nachricht;
private GrafikView view; private GrafikView view;
private GrafikModel model;
public TransmitterInterface transmitterInterface; public TransmitterInterface transmitterInterface;
public Server server; public Server server;
public Client client; public Client client;


public CommandSend(GrafikView view)
public CommandSend(GrafikView view, GrafikModel model)
{ {
this.view = view; this.view = view;
this.model = model;
//ToDo: Hier muss auch der gFrame referenziert werden //ToDo: Hier muss auch der gFrame referenziert werden
//this.eingabeFeld = view.getTfNachricht(); //this.eingabeFeld = view.getTfNachricht();
transmitterInterface = null; transmitterInterface = null;
public void execute() public void execute()
{ {
lg.info("wir sind drin"); lg.info("wir sind drin");
Figur aktuelleFigur = model.getFiguren().getLast();
transmitterInterface.send(aktuelleFigur);
//ToDo in dieser methode muss die Figur serialisiert werden und zum //ToDo in dieser methode muss die Figur serialisiert werden und zum
//übermitteln bereitgestellt werden //übermitteln bereitgestellt werden

+ 24
- 12
src/ChatProgramm/model/Transmitter.java View File

* *
* @author ahren * @author ahren
*/ */
public abstract class Transmitter implements Runnable, Subscriber<String>, TransmitterInterface {
public abstract class Transmitter implements Runnable, Subscriber<Figur>, TransmitterInterface {


static final int timeout = 60000; static final int timeout = 60000;
private static final int PORT = 35000; private static final int PORT = 35000;
lg.info("Initialisiere reader und writer"); lg.info("Initialisiere reader und writer");
InputStream is = socket.getInputStream(); InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream(); OutputStream os = socket.getOutputStream();

// Bruh im ernst mann muss zuerst den writer und dann den reader initialisieren
// andersrum ist das blockierend weil die Streams von hinten nach vorne
// gelesen werden
writer = new ObjectOutputStream(os);
writer.flush();
reader = new ObjectInputStream(is);
lg.info("1");
BufferedOutputStream bos = new BufferedOutputStream(os);
BufferedInputStream bis = new BufferedInputStream(is);
lg.info("2");
// InputStreamReader isr = new InputStreamReader(is, "UTF-8");
// OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");

reader = new ObjectInputStream(bis);
writer = new ObjectOutputStream(bos);
lg.info("Reader / Writer Initialisierung abgeschlossen"); lg.info("Reader / Writer Initialisierung abgeschlossen");
startempfangen(); startempfangen();
lg.info("Warte auf Nachricht"); lg.info("Warte auf Nachricht");
figurPublisher.submit(figur); figurPublisher.submit(figur);
} }
public Figur receive(){ public Figur receive(){
Object receivedObject;
try {
receivedObject = reader.readObject();
if (receivedObject instanceof Figur) {
Figur receivedFigur = (Figur) receivedObject;
// Verarbeiten Sie die empfangene Figur
}
} catch (IOException ex) {
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
}
try { try {
figur = (Figur) reader.readObject(); figur = (Figur) reader.readObject();
if(!txtNachricht.isEmpty()){ if(!txtNachricht.isEmpty()){
} }


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



Loading…
Cancel
Save