Initial commit. Teste efi.git.
Programm fertig gestellt.
This commit is contained in:
parent
dc9d1d749a
commit
0b043a0715
@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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 chatprogramm;
|
package chatprogramm;
|
||||||
|
|
||||||
import chatprogramm.controller.ConnectController;
|
import chatprogramm.controller.ConnectController;
|
||||||
@ -13,20 +7,27 @@ import chatprogramm.model.Transmitter;
|
|||||||
import chatprogramm.view.ChatView;
|
import chatprogramm.view.ChatView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
*
|
||||||
* @author le
|
* @author Marian
|
||||||
*/
|
*/
|
||||||
public class Start
|
public class Start {
|
||||||
{
|
|
||||||
public Start()
|
public Start()
|
||||||
{
|
{
|
||||||
ChatView view = new ChatView();
|
ChatView view = new ChatView();
|
||||||
Transmitter model = new Transmitter();
|
Transmitter model = new Transmitter();
|
||||||
ConnectController conCon = new ConnectController(view, model);
|
|
||||||
ReceiveAdapterController reiAdapCon = new ReceiveAdapterController(view, model);
|
|
||||||
SendController sendCon = new SendController(view, model);
|
|
||||||
view.setVisible(true);
|
|
||||||
|
|
||||||
|
ConnectController controllerConnect = new ConnectController(model, view);
|
||||||
|
controllerConnect.registerEvents();
|
||||||
|
|
||||||
|
SendController controllerSend = new SendController(model, view);
|
||||||
|
controllerSend.registerEvents();
|
||||||
|
|
||||||
|
ReceiveAdapterController rxAdapter = new ReceiveAdapterController(view);
|
||||||
|
model.addObserver(rxAdapter);
|
||||||
|
|
||||||
|
view.setTitle("ICQ 0.1 xD");
|
||||||
|
view.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +35,7 @@ public class Start
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
new Start();
|
Start start = new Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,87 +1,95 @@
|
|||||||
/*
|
|
||||||
* 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 chatprogramm.controller;
|
package chatprogramm.controller;
|
||||||
|
|
||||||
import chatprogramm.logger.OhmLogger;
|
|
||||||
import chatprogramm.model.Transmitter;
|
import chatprogramm.model.Transmitter;
|
||||||
|
import chatprogramm.logger.OhmLogger;
|
||||||
import chatprogramm.view.ChatView;
|
import chatprogramm.view.ChatView;
|
||||||
import java.io.IOException;
|
import java.awt.event.ActionEvent;
|
||||||
import java.util.logging.Level;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Gerhard
|
* @author Marian
|
||||||
*/
|
*/
|
||||||
public class ConnectController
|
public class ConnectController implements ActionListener
|
||||||
{
|
{
|
||||||
private ChatView view;
|
|
||||||
private Transmitter model;
|
private Transmitter model;
|
||||||
private static final Logger logger = OhmLogger.getLogger();
|
private ChatView view;
|
||||||
private String ip = null;
|
private static Logger logger = OhmLogger.getLogger();
|
||||||
private int port = 0;
|
|
||||||
|
|
||||||
public ConnectController(ChatView view, Transmitter model)
|
public ConnectController(Transmitter m, ChatView v)
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.model = m;
|
||||||
this.model = model;
|
this.view = v;
|
||||||
chooseConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void chooseConnection()
|
public void registerEvents()
|
||||||
{
|
{
|
||||||
Object[] options = {"Client", "Server"};
|
this.view.getBtConnect().addActionListener(this);
|
||||||
int choice = JOptionPane.showOptionDialog(view, "Wähle deine Verbindungsart:", "Client oder Server", 0, 1, null, options, null);
|
this.view.getRbClient().addActionListener(this);
|
||||||
|
this.view.getRbServer().addActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
if(choice == 1)
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent ae)
|
||||||
{
|
{
|
||||||
logger.info("Server");
|
Object o = ae.getSource();
|
||||||
String port = JOptionPane.showInputDialog(view, "PORT eingeben");
|
|
||||||
|
|
||||||
logger.info("Port für Server ist: localhost:" + port);
|
if (o == view.getBtConnect()) {
|
||||||
startServer();
|
int port = -1;
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.info("Client");
|
|
||||||
port = Integer.parseInt(JOptionPane.showInputDialog(view, "PORT eingeben"));
|
|
||||||
ip = JOptionPane.showInputDialog(view, "IP vom Server bitte");
|
|
||||||
|
|
||||||
logger.info("Client IP Adresse und Port ist: " + ip + ":" + port);
|
|
||||||
startClient();
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
port = Integer.parseInt(view.getTfPort().getText());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
JOptionPane.showMessageDialog(view, "Port ungültig! Muss eine Zahl sein");
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (view.getRbClient().isSelected() && (validIP(view.getTfIP().getText()) == false)) {
|
||||||
|
JOptionPane.showMessageDialog(view, "Ungültige IP-Adresse!");
|
||||||
|
logger.severe("IP-Adresse ungültig");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startServer()
|
model.connectToPeer(view.getRbServer().isSelected(), view.getTfIP().getText(), port);
|
||||||
{
|
|
||||||
try
|
view.getRbClient().setEnabled(false);
|
||||||
{
|
view.getRbServer().setEnabled(false);
|
||||||
model.createServer(port);
|
view.getTfIP().setEnabled(false);
|
||||||
}
|
view.getTfPort().setEnabled(false);
|
||||||
catch (IOException ex)
|
} else {
|
||||||
{
|
view.getTfIP().setEnabled(view.getRbClient().isSelected());
|
||||||
Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startClient()
|
private boolean validIP (String ip) {
|
||||||
{
|
try {
|
||||||
try
|
if ( ip == null || ip.isEmpty() ) {
|
||||||
{
|
return false;
|
||||||
model.createClient(port, ip);
|
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
|
||||||
{
|
String[] parts = ip.split( "\\." );
|
||||||
Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex);
|
if ( parts.length != 4 ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( String s : parts ) {
|
||||||
|
int i = Integer.parseInt( s );
|
||||||
|
if ( (i < 0) || (i > 255) ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( ip.endsWith(".") ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,28 @@
|
|||||||
/*
|
|
||||||
* 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 chatprogramm.controller;
|
package chatprogramm.controller;
|
||||||
|
|
||||||
import chatprogramm.model.Transmitter;
|
|
||||||
import chatprogramm.view.ChatView;
|
import chatprogramm.view.ChatView;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Gerhard
|
* @author Marian
|
||||||
*/
|
*/
|
||||||
public class ReceiveAdapterController implements Observer
|
public class ReceiveAdapterController implements Observer
|
||||||
{
|
{
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
private Transmitter model;
|
|
||||||
|
|
||||||
public ReceiveAdapterController(ChatView view, Transmitter model)
|
public ReceiveAdapterController(ChatView view)
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.model = model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg)
|
public void update(Observable observable, Object object)
|
||||||
{
|
{
|
||||||
|
String msg = (String)object;
|
||||||
|
|
||||||
|
view.getTaCommunication().append(msg + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,35 @@
|
|||||||
/*
|
|
||||||
* 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 chatprogramm.controller;
|
package chatprogramm.controller;
|
||||||
|
|
||||||
import chatprogramm.model.Transmitter;
|
import chatprogramm.model.Transmitter;
|
||||||
import chatprogramm.view.ChatView;
|
import chatprogramm.view.ChatView;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Gerhard
|
* @author Marian
|
||||||
*/
|
*/
|
||||||
public class SendController
|
public class SendController implements ActionListener
|
||||||
{
|
{
|
||||||
private ChatView view;
|
|
||||||
private Transmitter model;
|
private Transmitter model;
|
||||||
|
private ChatView view;
|
||||||
|
|
||||||
public SendController(ChatView view, Transmitter model)
|
public SendController(Transmitter m, ChatView v)
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.model = m;
|
||||||
this.model = model;
|
this.view = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEvents()
|
||||||
|
{
|
||||||
|
this.view.getBtSend().addActionListener(this);
|
||||||
|
this.view.getTfMessage().addActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent ae)
|
||||||
|
{
|
||||||
|
model.sendMessage(view.getTfMessage().getText());
|
||||||
|
view.getTfMessage().setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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 chatprogramm.model;
|
package chatprogramm.model;
|
||||||
|
|
||||||
import chatprogramm.logger.OhmLogger;
|
import chatprogramm.logger.OhmLogger;
|
||||||
@ -14,54 +8,128 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
*
|
||||||
* @author le
|
* @author Marian
|
||||||
*/
|
*/
|
||||||
public class Client
|
public class Client extends Observable implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger lg = OhmLogger.getLogger();
|
private Socket socket;
|
||||||
private static int PORT = 35000;
|
private BufferedReader reader;
|
||||||
private static String IP_ADRESSE = "127.0.0.1";
|
private PrintWriter writer;
|
||||||
|
private boolean ready;
|
||||||
|
private Thread thd;
|
||||||
|
private String ip;
|
||||||
|
private int port;
|
||||||
|
private static Logger logger = OhmLogger.getLogger();
|
||||||
|
|
||||||
public Client(int port, String ip) throws IOException
|
|
||||||
|
public Client(String ip, int port)
|
||||||
{
|
{
|
||||||
if(port != 0) {this.PORT = port;};
|
this.ip = ip;
|
||||||
if(ip != null | ip != "") {this.IP_ADRESSE = ip;};
|
this.port = port;
|
||||||
|
this.socket = null;
|
||||||
lg.info("Client: verbinde ...");
|
this.reader = null;
|
||||||
Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert!
|
this.writer = null;
|
||||||
lg.info("Client: Verbindung hergestellt");
|
this.ready = false;
|
||||||
InputStream iStream = s.getInputStream();
|
this.thd = null;
|
||||||
OutputStream oStream = s.getOutputStream();
|
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8");
|
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8");
|
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(isr);
|
|
||||||
//BufferedWriter out = new BufferedWriter(osr);
|
|
||||||
PrintWriter out = new PrintWriter(osr);
|
|
||||||
|
|
||||||
lg.info("Client: Stream initialisiert");
|
|
||||||
|
|
||||||
out.println("Hallo Du Server Du - ich bin der client");
|
|
||||||
out.flush(); // wirklich absenden!!
|
|
||||||
|
|
||||||
lg.info("Client: Nachricht versendet");
|
|
||||||
|
|
||||||
String quittung = in.readLine(); // Achtung blockiert
|
|
||||||
lg.info("Client: Quittung empfangen");
|
|
||||||
|
|
||||||
System.out.println("Client: Quittung EMPFANGEN - " + quittung);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
out.close();
|
|
||||||
in.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
if (thd == null) {
|
||||||
|
thd = new Thread(this);
|
||||||
|
thd.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String msg)
|
||||||
|
{
|
||||||
|
if (ready) {
|
||||||
|
writer.println(msg);
|
||||||
|
writer.flush();
|
||||||
|
} else {
|
||||||
|
logger.warning("Server not ready to send message. Connect first");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
logger.info("Running client...");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (socket == null) {
|
||||||
|
try {
|
||||||
|
socket = new Socket(ip, port);
|
||||||
|
logger.info("Connected to server");
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.getMessage());
|
||||||
|
socket = null;
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream iStream;
|
||||||
|
try {
|
||||||
|
iStream = socket.getInputStream();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OutputStream oStream;
|
||||||
|
try {
|
||||||
|
oStream = socket.getOutputStream();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStreamReader isr;
|
||||||
|
try {
|
||||||
|
isr = new InputStreamReader(iStream, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
logger.severe(e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OutputStreamWriter osr;
|
||||||
|
try {
|
||||||
|
osr = new OutputStreamWriter(oStream, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
logger.severe(e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reader = new BufferedReader(isr);
|
||||||
|
writer = new PrintWriter(osr);
|
||||||
|
|
||||||
|
ready = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ready) {
|
||||||
|
String msg;
|
||||||
|
try {
|
||||||
|
logger.info("Waiting for message");
|
||||||
|
msg = reader.readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setChanged();
|
||||||
|
this.notifyObservers(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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 chatprogramm.model;
|
package chatprogramm.model;
|
||||||
|
|
||||||
import chatprogramm.logger.OhmLogger;
|
import chatprogramm.logger.OhmLogger;
|
||||||
@ -14,54 +8,140 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
*
|
||||||
* @author le
|
* @author Marian
|
||||||
*/
|
*/
|
||||||
public class Server
|
public class Server extends Observable implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger lg = OhmLogger.getLogger();
|
private int port;
|
||||||
private static int PORT = 35000;
|
private ServerSocket server;
|
||||||
|
private Socket client;
|
||||||
|
private static Logger logger = OhmLogger.getLogger();
|
||||||
|
private BufferedReader reader;
|
||||||
|
private PrintWriter writer;
|
||||||
|
private volatile boolean ready;
|
||||||
|
private Thread thd;
|
||||||
|
private static final SimpleDateFormat sdf = new SimpleDateFormat("HH.mm.ss");
|
||||||
|
|
||||||
public Server(int port) throws IOException
|
|
||||||
|
public Server(int port)
|
||||||
{
|
{
|
||||||
if(port != 0)
|
this.port = port;
|
||||||
{
|
this.server = null;
|
||||||
this.PORT = port;
|
this.client = null;
|
||||||
|
this.reader = null;
|
||||||
|
this.writer = null;
|
||||||
|
this.ready = false;
|
||||||
|
this.thd = null;
|
||||||
}
|
}
|
||||||
ServerSocket sSocket = new ServerSocket(PORT);
|
|
||||||
lg.info("Server: Warte auf Verbindung ...");
|
|
||||||
Socket s = sSocket.accept(); // Achtung: blockiert!
|
|
||||||
lg.info("Server: Verbindung akzeptiert");
|
|
||||||
InputStream iStream = s.getInputStream();
|
|
||||||
OutputStream oStream = s.getOutputStream();
|
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8");
|
public void init()
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8");
|
{
|
||||||
|
if (thd == null) {
|
||||||
|
thd = new Thread(this);
|
||||||
|
thd.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(isr);
|
@Override
|
||||||
//BufferedWriter out = new BufferedWriter(osr);
|
public void run()
|
||||||
PrintWriter out = new PrintWriter(osr);
|
{
|
||||||
|
logger.info("Running server...");
|
||||||
|
|
||||||
lg.info("Server: Stream initialisiert");
|
while (true)
|
||||||
lg.info("Server: warte auf Nachricht ...");
|
{
|
||||||
|
if (server == null) {
|
||||||
|
try {
|
||||||
|
server = new ServerSocket(port);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String nachricht = in.readLine(); // Achtung blockiert
|
logger.info("Waiting for client to connect");
|
||||||
lg.info("Server: Nachricht empfangen");
|
try {
|
||||||
|
client = server.accept();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.info("Client connected");
|
||||||
|
|
||||||
System.out.println("Server: NACHRICHT EMPFANGEN - " + nachricht);
|
InputStream iStream;
|
||||||
|
try {
|
||||||
|
iStream = client.getInputStream();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OutputStream oStream;
|
||||||
|
try {
|
||||||
|
oStream = client.getOutputStream();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
out.println("Server -> ich habe die Nachricht erhalten");
|
InputStreamReader isr;
|
||||||
lg.info("Server: Quittung versendet");
|
try {
|
||||||
|
isr = new InputStreamReader(iStream, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OutputStreamWriter osr;
|
||||||
|
try {
|
||||||
|
osr = new OutputStreamWriter(oStream, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
out.flush(); // wirklich absenden!!
|
reader = new BufferedReader(isr);
|
||||||
|
writer = new PrintWriter(osr);
|
||||||
|
|
||||||
out.close();
|
ready = true;
|
||||||
in.close();
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ready) {
|
||||||
|
try {
|
||||||
|
logger.info("Waiting for message");
|
||||||
|
String msg = reader.readLine();
|
||||||
|
if (msg == null) {
|
||||||
|
ready = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setChanged();
|
||||||
|
this.notifyObservers(msg);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe(e.toString());
|
||||||
|
ready = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String msg)
|
||||||
|
{
|
||||||
|
if (ready) {
|
||||||
|
writer.println(msg);
|
||||||
|
writer.flush();
|
||||||
|
} else {
|
||||||
|
logger.warning("Server not ready to send message. Connect first");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,78 @@
|
|||||||
/*
|
|
||||||
* 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 chatprogramm.model;
|
package chatprogramm.model;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
import chatprogramm.controller.ReceiveAdapterController;
|
||||||
|
import chatprogramm.logger.OhmLogger;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.Observer;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Gerhard
|
* @author Marian
|
||||||
*/
|
*/
|
||||||
public class Transmitter
|
public class Transmitter extends Observable implements Observer
|
||||||
{
|
{
|
||||||
Server server;
|
boolean connected;
|
||||||
Client client;
|
Server srv;
|
||||||
|
Client cli;
|
||||||
|
boolean mode;
|
||||||
|
boolean initialized;
|
||||||
|
ReceiveAdapterController Adapter;
|
||||||
|
private static Logger logger = OhmLogger.getLogger();
|
||||||
|
|
||||||
public Transmitter()
|
public Transmitter()
|
||||||
{
|
{
|
||||||
|
connected = false;
|
||||||
|
mode = false;
|
||||||
|
initialized = false;
|
||||||
|
srv = null;
|
||||||
|
cli = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createServer(int port) throws IOException
|
public void connectToPeer(boolean mode, String ip, int port)
|
||||||
{
|
{
|
||||||
server = new Server(port);
|
if (initialized) {
|
||||||
|
logger.info("Chat already running");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createClient(int port, String ip) throws IOException
|
this.mode = mode;
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
logger.info("Running as server");
|
||||||
|
srv = new Server(port);
|
||||||
|
srv.addObserver(this);
|
||||||
|
srv.init();
|
||||||
|
} else {
|
||||||
|
logger.info("Running as client");
|
||||||
|
cli = new Client(ip, port);
|
||||||
|
cli.addObserver(this);
|
||||||
|
cli.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String msg)
|
||||||
{
|
{
|
||||||
client = new Client(port, ip);
|
if (!initialized) {
|
||||||
|
logger.warning("Chat not initialized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
srv.sendMessage(msg);
|
||||||
|
} else {
|
||||||
|
cli.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Observable o, Object o1)
|
||||||
|
{
|
||||||
|
this.setChanged();
|
||||||
|
this.notifyObservers(o1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||||
<NonVisualComponents>
|
<NonVisualComponents>
|
||||||
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
|
<Component class="javax.swing.ButtonGroup" name="bgSelect">
|
||||||
<SubComponents>
|
</Component>
|
||||||
<Menu class="javax.swing.JMenu" name="jMenu2">
|
|
||||||
<Properties>
|
|
||||||
<Property name="text" type="java.lang.String" value="File"/>
|
|
||||||
</Properties>
|
|
||||||
</Menu>
|
|
||||||
<Menu class="javax.swing.JMenu" name="jMenu3">
|
|
||||||
<Properties>
|
|
||||||
<Property name="text" type="java.lang.String" value="Edit"/>
|
|
||||||
</Properties>
|
|
||||||
</Menu>
|
|
||||||
</SubComponents>
|
|
||||||
</Menu>
|
|
||||||
</NonVisualComponents>
|
</NonVisualComponents>
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
<SyntheticProperties>
|
<SyntheticProperties>
|
||||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
|
|
||||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||||
<SyntheticProperty name="generateCenter" type="boolean" value="true"/>
|
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||||
</SyntheticProperties>
|
</SyntheticProperties>
|
||||||
<AuxValues>
|
<AuxValues>
|
||||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||||
@ -35,51 +22,72 @@
|
|||||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-112,0,0,2,88"/>
|
|
||||||
</AuxValues>
|
</AuxValues>
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
<Layout>
|
||||||
<SubComponents>
|
<DimensionLayout dim="0">
|
||||||
<Container class="javax.swing.JLayeredPane" name="chatControll">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Constraints>
|
<Group type="102" alignment="1" attributes="0">
|
||||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<BorderConstraints direction="Last"/>
|
<Group type="103" groupAlignment="1" attributes="0">
|
||||||
</Constraint>
|
<Group type="102" alignment="0" attributes="0">
|
||||||
</Constraints>
|
<Component id="lbPort" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
|
<Component id="tfPort" min="-2" pref="61" max="-2" attributes="0"/>
|
||||||
<SubComponents>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component class="javax.swing.JButton" name="btnSend">
|
<Component id="lbIP" min="-2" max="-2" attributes="0"/>
|
||||||
<Properties>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Property name="text" type="java.lang.String" value="send"/>
|
<Component id="tfIP" min="-2" pref="191" max="-2" attributes="0"/>
|
||||||
</Properties>
|
<EmptySpace pref="34" max="32767" attributes="0"/>
|
||||||
</Component>
|
<Component id="btConnect" min="-2" max="-2" attributes="0"/>
|
||||||
<Component class="javax.swing.JButton" name="btnClear">
|
</Group>
|
||||||
<Properties>
|
<Group type="102" alignment="0" attributes="0">
|
||||||
<Property name="text" type="java.lang.String" value="clear"/>
|
<Component id="rbClient" min="-2" pref="64" max="-2" attributes="0"/>
|
||||||
</Properties>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
</Component>
|
<Component id="rbServer" min="-2" max="-2" attributes="0"/>
|
||||||
<Component class="javax.swing.JButton" name="btnServer">
|
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||||
<Properties>
|
</Group>
|
||||||
<Property name="text" type="java.lang.String" value="jButton1"/>
|
<Component id="jScrollPane1" alignment="1" max="32767" attributes="0"/>
|
||||||
</Properties>
|
<Group type="102" alignment="0" attributes="0">
|
||||||
</Component>
|
<Component id="tfMessage" max="32767" attributes="0"/>
|
||||||
<Component class="javax.swing.JButton" name="jButton1">
|
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||||
<Properties>
|
<Component id="btSend" min="-2" max="-2" attributes="0"/>
|
||||||
<Property name="text" type="java.lang.String" value="jButton1"/>
|
</Group>
|
||||||
</Properties>
|
</Group>
|
||||||
</Component>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
</SubComponents>
|
</Group>
|
||||||
</Container>
|
<Component id="jSeparator2" alignment="0" max="32767" attributes="0"/>
|
||||||
<Container class="javax.swing.JLayeredPane" name="chatContent">
|
</Group>
|
||||||
<Constraints>
|
</DimensionLayout>
|
||||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
<DimensionLayout dim="1">
|
||||||
<BorderConstraints direction="Center"/>
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
</Constraint>
|
<Group type="102" alignment="0" attributes="0">
|
||||||
</Constraints>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="jScrollPane1" pref="134" max="32767" attributes="0"/>
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
|
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||||
<Property name="axis" type="int" value="3"/>
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="tfMessage" alignment="3" min="-2" pref="25" max="-2" attributes="0"/>
|
||||||
|
<Component id="btSend" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||||
|
<Component id="jSeparator2" min="-2" pref="6" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="rbServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="rbClient" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="lbPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="tfPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="tfIP" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lbIP" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btConnect" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
</Layout>
|
</Layout>
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||||
@ -89,7 +97,7 @@
|
|||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Component class="javax.swing.JTextArea" name="taEmpfangen">
|
<Component class="javax.swing.JTextArea" name="taCommunication">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="columns" type="int" value="20"/>
|
<Property name="columns" type="int" value="20"/>
|
||||||
<Property name="rows" type="int" value="5"/>
|
<Property name="rows" type="int" value="5"/>
|
||||||
@ -97,22 +105,65 @@
|
|||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
|
<Component class="javax.swing.JTextField" name="tfMessage">
|
||||||
<AuxValues>
|
</Component>
|
||||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
<Component class="javax.swing.JButton" name="btSend">
|
||||||
</AuxValues>
|
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
|
||||||
<SubComponents>
|
|
||||||
<Component class="javax.swing.JTextArea" name="taSenden">
|
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="columns" type="int" value="20"/>
|
<Property name="text" type="java.lang.String" value="send"/>
|
||||||
<Property name="rows" type="int" value="5"/>
|
|
||||||
</Properties>
|
</Properties>
|
||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
<Component class="javax.swing.JTextField" name="tfPort">
|
||||||
</Container>
|
<Properties>
|
||||||
</SubComponents>
|
<Property name="text" type="java.lang.String" value="3210"/>
|
||||||
</Container>
|
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lbPort">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="Port:"/>
|
||||||
|
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lbIP">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="IP:"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JTextField" name="tfIP">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="127.0.0.1"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JButton" name="btConnect">
|
||||||
|
<Properties>
|
||||||
|
<Property name="text" type="java.lang.String" value="connect"/>
|
||||||
|
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JRadioButton" name="rbClient">
|
||||||
|
<Properties>
|
||||||
|
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
|
||||||
|
<ComponentRef name="bgSelect"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="selected" type="boolean" value="true"/>
|
||||||
|
<Property name="text" type="java.lang.String" value="Client"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rbClientActionPerformed"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JRadioButton" name="rbServer">
|
||||||
|
<Properties>
|
||||||
|
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
|
||||||
|
<ComponentRef name="bgSelect"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="text" type="java.lang.String" value="Server"/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rbServerActionPerformed"/>
|
||||||
|
</Events>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JSeparator" name="jSeparator2">
|
||||||
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -7,47 +7,84 @@ package chatprogramm.view;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Gerhard
|
* @author max
|
||||||
*/
|
*/
|
||||||
public class ChatView extends javax.swing.JFrame
|
public class ChatView extends javax.swing.JFrame {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @return the btnClear
|
* @return the rbClient
|
||||||
*/
|
*/
|
||||||
public javax.swing.JButton getBtnClear()
|
public javax.swing.JRadioButton getRbClient() {
|
||||||
{
|
return rbClient;
|
||||||
return btnClear;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the btnSend
|
* @return the rbServer
|
||||||
*/
|
*/
|
||||||
public javax.swing.JButton getBtnSend()
|
public javax.swing.JRadioButton getRbServer() {
|
||||||
{
|
return rbServer;
|
||||||
return btnSend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the taEmpfangen
|
* @return the btConnect
|
||||||
*/
|
*/
|
||||||
public javax.swing.JTextArea getTaEmpfangen()
|
public javax.swing.JButton getBtConnect() {
|
||||||
{
|
return btConnect;
|
||||||
return taEmpfangen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the taSenden
|
* @return the btSend
|
||||||
*/
|
*/
|
||||||
public javax.swing.JTextArea getTaSenden()
|
public javax.swing.JButton getBtSend() {
|
||||||
{
|
return btSend;
|
||||||
return taSenden;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the lbIP
|
||||||
|
*/
|
||||||
|
public javax.swing.JLabel getLbIP() {
|
||||||
|
return lbIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the lbPort
|
||||||
|
*/
|
||||||
|
public javax.swing.JLabel getLbPort() {
|
||||||
|
return lbPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the taCommunication
|
||||||
|
*/
|
||||||
|
public javax.swing.JTextArea getTaCommunication() {
|
||||||
|
return taCommunication;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the tfIP
|
||||||
|
*/
|
||||||
|
public javax.swing.JTextField getTfIP() {
|
||||||
|
return tfIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the tfMessage
|
||||||
|
*/
|
||||||
|
public javax.swing.JTextField getTfMessage() {
|
||||||
|
return tfMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the tfPort
|
||||||
|
*/
|
||||||
|
public javax.swing.JTextField getTfPort() {
|
||||||
|
return tfPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form ChatView
|
* Creates new form ChatView
|
||||||
*/
|
*/
|
||||||
public ChatView()
|
public ChatView() {
|
||||||
{
|
|
||||||
initComponents();
|
initComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,131 +95,174 @@ public class ChatView extends javax.swing.JFrame
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents()
|
private void initComponents() {
|
||||||
{
|
|
||||||
|
|
||||||
chatControll = new javax.swing.JLayeredPane();
|
bgSelect = new javax.swing.ButtonGroup();
|
||||||
btnSend = new javax.swing.JButton();
|
|
||||||
btnClear = new javax.swing.JButton();
|
|
||||||
btnServer = new javax.swing.JButton();
|
|
||||||
jButton1 = new javax.swing.JButton();
|
|
||||||
chatContent = new javax.swing.JLayeredPane();
|
|
||||||
jScrollPane1 = new javax.swing.JScrollPane();
|
jScrollPane1 = new javax.swing.JScrollPane();
|
||||||
taEmpfangen = new javax.swing.JTextArea();
|
taCommunication = new javax.swing.JTextArea();
|
||||||
jScrollPane2 = new javax.swing.JScrollPane();
|
tfMessage = new javax.swing.JTextField();
|
||||||
taSenden = new javax.swing.JTextArea();
|
btSend = new javax.swing.JButton();
|
||||||
jMenuBar1 = new javax.swing.JMenuBar();
|
tfPort = new javax.swing.JTextField();
|
||||||
jMenu2 = new javax.swing.JMenu();
|
lbPort = new javax.swing.JLabel();
|
||||||
jMenu3 = new javax.swing.JMenu();
|
lbIP = new javax.swing.JLabel();
|
||||||
|
tfIP = new javax.swing.JTextField();
|
||||||
|
btConnect = new javax.swing.JButton();
|
||||||
|
rbClient = new javax.swing.JRadioButton();
|
||||||
|
rbServer = new javax.swing.JRadioButton();
|
||||||
|
jSeparator2 = new javax.swing.JSeparator();
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
chatControll.setLayout(new java.awt.FlowLayout());
|
taCommunication.setColumns(20);
|
||||||
|
taCommunication.setRows(5);
|
||||||
|
jScrollPane1.setViewportView(taCommunication);
|
||||||
|
|
||||||
btnSend.setText("send");
|
btSend.setText("send");
|
||||||
chatControll.add(btnSend);
|
|
||||||
|
|
||||||
btnClear.setText("clear");
|
tfPort.setText("3210");
|
||||||
chatControll.add(btnClear);
|
tfPort.setToolTipText("");
|
||||||
|
|
||||||
btnServer.setText("jButton1");
|
lbPort.setText("Port:");
|
||||||
chatControll.add(btnServer);
|
lbPort.setToolTipText("");
|
||||||
|
|
||||||
jButton1.setText("jButton1");
|
lbIP.setText("IP:");
|
||||||
chatControll.add(jButton1);
|
|
||||||
|
|
||||||
getContentPane().add(chatControll, java.awt.BorderLayout.PAGE_END);
|
tfIP.setText("127.0.0.1");
|
||||||
|
|
||||||
chatContent.setLayout(new javax.swing.BoxLayout(chatContent, javax.swing.BoxLayout.PAGE_AXIS));
|
btConnect.setText("connect");
|
||||||
|
btConnect.setToolTipText("");
|
||||||
|
|
||||||
taEmpfangen.setColumns(20);
|
bgSelect.add(rbClient);
|
||||||
taEmpfangen.setRows(5);
|
rbClient.setSelected(true);
|
||||||
jScrollPane1.setViewportView(taEmpfangen);
|
rbClient.setText("Client");
|
||||||
|
rbClient.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
rbClientActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
chatContent.add(jScrollPane1);
|
bgSelect.add(rbServer);
|
||||||
|
rbServer.setText("Server");
|
||||||
|
rbServer.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
rbServerActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
taSenden.setColumns(20);
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||||
taSenden.setRows(5);
|
getContentPane().setLayout(layout);
|
||||||
jScrollPane2.setViewportView(taSenden);
|
layout.setHorizontalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
chatContent.add(jScrollPane2);
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
getContentPane().add(chatContent, java.awt.BorderLayout.CENTER);
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||||
|
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||||
jMenu2.setText("File");
|
.addComponent(lbPort)
|
||||||
jMenuBar1.add(jMenu2);
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addComponent(tfPort, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
jMenu3.setText("Edit");
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
jMenuBar1.add(jMenu3);
|
.addComponent(lbIP)
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
setJMenuBar(jMenuBar1);
|
.addComponent(tfIP, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
|
||||||
|
.addComponent(btConnect))
|
||||||
|
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||||
|
.addComponent(rbClient, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addComponent(rbServer)
|
||||||
|
.addGap(0, 0, Short.MAX_VALUE))
|
||||||
|
.addComponent(jScrollPane1)
|
||||||
|
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||||
|
.addComponent(tfMessage)
|
||||||
|
.addGap(18, 18, 18)
|
||||||
|
.addComponent(btSend)))
|
||||||
|
.addContainerGap())
|
||||||
|
.addComponent(jSeparator2)
|
||||||
|
);
|
||||||
|
layout.setVerticalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addGroup(layout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
|
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
|
||||||
|
.addGap(18, 18, 18)
|
||||||
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(tfMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(btSend))
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||||
|
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addGap(1, 1, 1)
|
||||||
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(rbServer)
|
||||||
|
.addComponent(rbClient))
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||||
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(lbPort)
|
||||||
|
.addComponent(tfPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(tfIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(lbIP)
|
||||||
|
.addComponent(btConnect))
|
||||||
|
.addContainerGap())
|
||||||
|
);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
setLocationRelativeTo(null);
|
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
|
private void rbClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbClientActionPerformed
|
||||||
|
// TODO add your handling code here:
|
||||||
|
}//GEN-LAST:event_rbClientActionPerformed
|
||||||
|
|
||||||
|
private void rbServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbServerActionPerformed
|
||||||
|
// TODO add your handling code here:
|
||||||
|
}//GEN-LAST:event_rbServerActionPerformed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String args[])
|
public static void main(String args[]) {
|
||||||
{
|
|
||||||
/* Set the Nimbus look and feel */
|
/* Set the Nimbus look and feel */
|
||||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||||
*/
|
*/
|
||||||
try
|
try {
|
||||||
{
|
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
|
if ("Nimbus".equals(info.getName())) {
|
||||||
{
|
|
||||||
if ("Nimbus".equals(info.getName()))
|
|
||||||
{
|
|
||||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (ClassNotFoundException ex) {
|
||||||
catch (ClassNotFoundException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
}
|
} catch (InstantiationException ex) {
|
||||||
catch (InstantiationException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
}
|
} catch (IllegalAccessException ex) {
|
||||||
catch (IllegalAccessException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
}
|
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||||
catch (javax.swing.UnsupportedLookAndFeelException ex)
|
|
||||||
{
|
|
||||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
/* Create and display the form */
|
/* Create and display the form */
|
||||||
java.awt.EventQueue.invokeLater(new Runnable()
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||||
{
|
public void run() {
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
new ChatView().setVisible(true);
|
new ChatView().setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JButton btnClear;
|
private javax.swing.ButtonGroup bgSelect;
|
||||||
private javax.swing.JButton btnSend;
|
private javax.swing.JButton btConnect;
|
||||||
private javax.swing.JButton btnServer;
|
private javax.swing.JButton btSend;
|
||||||
private javax.swing.JLayeredPane chatContent;
|
|
||||||
private javax.swing.JLayeredPane chatControll;
|
|
||||||
private javax.swing.JButton jButton1;
|
|
||||||
private javax.swing.JMenu jMenu2;
|
|
||||||
private javax.swing.JMenu jMenu3;
|
|
||||||
private javax.swing.JMenuBar jMenuBar1;
|
|
||||||
private javax.swing.JScrollPane jScrollPane1;
|
private javax.swing.JScrollPane jScrollPane1;
|
||||||
private javax.swing.JScrollPane jScrollPane2;
|
private javax.swing.JSeparator jSeparator2;
|
||||||
private javax.swing.JTextArea taEmpfangen;
|
private javax.swing.JLabel lbIP;
|
||||||
private javax.swing.JTextArea taSenden;
|
private javax.swing.JLabel lbPort;
|
||||||
|
private javax.swing.JRadioButton rbClient;
|
||||||
|
private javax.swing.JRadioButton rbServer;
|
||||||
|
private javax.swing.JTextArea taCommunication;
|
||||||
|
private javax.swing.JTextField tfIP;
|
||||||
|
private javax.swing.JTextField tfMessage;
|
||||||
|
private javax.swing.JTextField tfPort;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user