123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- * 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;
-
- import chatprogramm.logger.OhmLogger;
- import chatprogramm.model.Transmitter;
- import chatprogramm.view.ChatView;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
-
- /**
- *
- * @author Gerhard
- */
- public class ConnectController
- {
- private ChatView view;
- private Transmitter model;
- private static final Logger logger = OhmLogger.getLogger();
- private String ip = null;
- private int port = 0;
-
- public ConnectController(ChatView view, Transmitter model)
- {
- this.view = view;
- this.model = model;
- chooseConnection();
- }
-
- void chooseConnection()
- {
- Object[] options = {"Client", "Server"};
- int choice = JOptionPane.showOptionDialog(view, "Wähle deine Verbindungsart:", "Client oder Server", 0, 1, null, options, null);
-
- if(choice == 1)
- {
- logger.info("Server");
- String port = JOptionPane.showInputDialog(view, "PORT eingeben");
-
- logger.info("Port für Server ist: localhost:" + port);
- startServer();
-
-
- }
- 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();
-
- }
-
- }
-
- public void startServer()
- {
- try
- {
- model.createServer(port);
- }
- catch (IOException ex)
- {
- Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- public void startClient()
- {
- try
- {
- model.createClient(port, ip);
- }
- catch (IOException ex)
- {
- Logger.getLogger(ConnectController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
|