|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kommunikation.transmitter;
-
- import java.util.Observable;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import kommunikation.logger.OhmLogger;
-
- /**
- *
- * @author Alexander_Christoph
- */
- public class Transmitter extends Observable implements Runnable
- {
- protected static final Logger lg = OhmLogger.getLogger();
- private Kommunikationspartner kom;
- private Boolean verbindung;
- private Thread thd;
-
- public Transmitter(int modus)
- {
- if (modus == 0)
- {
- kom = new Client();
- }
-
- if (modus == 1)
- {
- kom = new Server();
- }
-
- verbindung = false;
- thd = null;
- }
-
- public void start()
- {
- if (thd == null)
- {
- thd = new Thread(this);
- thd.start();
- }
-
- }
-
- @Override
- public void run()
- {
- while (true)
- {
- if (!verbindung)
- {
- kom.verbinde();
- verbindung = true;
- }
- synchronized (this)
- {
- kom.empfangen();
- }
- lg.info("empfangen");
- this.setChanged();
- this.notifyObservers();
- }
- }
-
- public void setIpPort(String ip, int port)
- {
- kom.setPort(port);
- kom.setIp(ip);
- }
-
- public void senden(Object nachricht)
- {
- if (verbindung)
- {
- kom.senden(nachricht);
- }
- else
- {
- JOptionPane.showMessageDialog(null, "Bauen Sie zuerst eine Verbindung auf", "Keine Verbindung", JOptionPane.INFORMATION_MESSAGE);
- }
- }
-
- public Object getNachricht()
- {
- return kom.getNachricht();
- }
-
- }
|