diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 1b6c36a..bd22d7e 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1,2 +1,2 @@ -compile.on.save=true -user.properties.file=C:\\Users\\ANDITYAARIFIANTO\\AppData\\Roaming\\NetBeans\\8.1\\build.properties +compile.on.save=true +user.properties.file=C:\\Users\\Ncisl\\AppData\\Roaming\\NetBeans\\8.1\\build.properties diff --git a/src/ConsoleApp/ConnectionThread.java b/src/ConsoleApp/ConnectionThread.java new file mode 100644 index 0000000..a2c12cf --- /dev/null +++ b/src/ConsoleApp/ConnectionThread.java @@ -0,0 +1,53 @@ +/* + * 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 ConsoleApp; + + +import java.io.IOException; +import java.net.Socket; +import java.util.logging.Level; +import java.util.logging.Logger; +import javaChat.Connection; + + + +/** + * + * @author lailis + */ +public class ConnectionThread { +private Socket client; +private Connection connection; + + public ConnectionThread (Socket newClient ) throws IOException{ + this.client = newClient; + connection = new Connection(client); + } + + public void run () { + try { + connection.startChat("Strat the Chat-----"); + System.out.println("-----------"); + System.out.println("new client connected"); + System.out.println("client information : "); + System.out.println(connection.getClientInformation()); + String inputan; + String message; + while ((inputan = connection.readStream())!= null && !inputan.equals("quit")){ + message = "Client " + connection.getIpClient() + "said : " + inputan; + System.out.println(message); + connection.sendToAll(message); + } + message = "Client from IP : " + connection.getIpClient() + "Quit from chat room "; + System.out.println(message); + connection.sendToAll(message); + connection.disconnect(); + } catch (IOException ex) { System.out.println("ERROR"); + } + } +} + diff --git a/src/ConsoleApp/ConsoleApplication.java b/src/ConsoleApp/ConsoleApplication.java new file mode 100644 index 0000000..8fb1a53 --- /dev/null +++ b/src/ConsoleApp/ConsoleApplication.java @@ -0,0 +1,63 @@ +/* + * 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 ConsoleApp; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javaChat.ClientConnection; +/** + * + * @author lailis + */ +public class ConsoleApplication { + private ClientConnection client; + + public class ReadInput extends Thread{ + public void run (){ + try { + String inputKeyboard; + do { + System.out.println(">> "); + inputKeyboard = client.inputString(); + client.writeStream(inputKeyboard); + } while (! inputKeyboard.equals("quit")); + client.disconnect(); + } catch (IOException ex) { + System.out.println("Error"); + } + } + } + + public class WriteOutput extends Thread{ + public void run (){ + try { + String inputan; + while ((inputan = client.readStream()) != null){ + System.out.println(inputan); + System.out.println(">> "); + } + } catch (IOException ex) { + System.out.println("Error"); + } + } + } + + public void startChat() { + try { + client = new ClientConnection(); + System.out.println("input server IP : "); + String ip = client.inputString(); + client.connect(ip); + } catch (IOException ex) { + System.out.println("ERROR"); + } + ReadInput in = new ReadInput(); + WriteOutput out = new WriteOutput(); + in.start(); + out.start(); + } +} + diff --git a/src/Driver/DriverClientConsole.java b/src/Driver/DriverClientConsole.java new file mode 100644 index 0000000..ff4c916 --- /dev/null +++ b/src/Driver/DriverClientConsole.java @@ -0,0 +1,20 @@ +/* + * 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 Driver; + +import ConsoleApp.ConsoleApplication; + +/** + * + * @author lailis + */ +public class DriverClientConsole { + public static void main(String[] args) { + ConsoleApplication app = new ConsoleApplication(); + app.startChat(); + } +} + diff --git a/src/Driver/DriverClientGUI.java b/src/Driver/DriverClientGUI.java new file mode 100644 index 0000000..5ea04dd --- /dev/null +++ b/src/Driver/DriverClientGUI.java @@ -0,0 +1,19 @@ +/* + * 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 Driver; + +import chatGUI.ChatController; + +/** + * + * @author lailis + */ +public class DriverClientGUI { + public static void main(String[] args) { + new ChatController(); + } +} + diff --git a/src/Driver/DriverServer.java b/src/Driver/DriverServer.java new file mode 100644 index 0000000..82e55bd --- /dev/null +++ b/src/Driver/DriverServer.java @@ -0,0 +1,33 @@ +/* + * 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 Driver; + +import ConsoleApp.ConnectionThread; +import java.io.IOException; +import javaChat.ServerConnection; + +/** + * + * @author lailis + * + */ +public class DriverServer { + public static void main(String[] args) { + try { + ServerConnection server = new ServerConnection(); + System.out.println("Server Information"); + System.out.println(server.getServerInformation()); + while (true){ + ConnectionThread connection = new ConnectionThread(server.getClient()); + connection.run(); + } + } catch (IOException ex) { + System.out.println("Error"); + } + } +} + + diff --git a/src/chatGUI/ChatController.java b/src/chatGUI/ChatController.java new file mode 100644 index 0000000..416273f --- /dev/null +++ b/src/chatGUI/ChatController.java @@ -0,0 +1,69 @@ +/* + * 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 chatGUI; + +import ConsoleApp.ConsoleApplication.WriteOutput; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import javaChat.ClientConnection; +import javax.swing.JOptionPane; + +/** + * + * @author lailis + */ +public class ChatController implements ActionListener { + private ChatView view; + private ClientConnection client; + + public ChatController() { + view = new ChatView(); + view.setVisible(true); + view.addListener(this); + client = null; + } + + @Override + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source.equals(view.getTextField())){ + if (client == null){ + try { + client = new ClientConnection(); + view.setTxAreaCaht(view.getStringChat()); + String ip = view.getStringChat(); + client.connect(ip); + WriteOutput w = new WriteOutput(); + w.start(); + } catch (IOException ex) { + JOptionPane.showMessageDialog(null, "Error"); + } + } + else { + String input = view.getStringChat(); + client.writeStream(input); + view.setTextFieldChat(""); + } + } + } + + public class WriteOutput extends Thread { + + public void run() { + try { + String inp; + while ((inp = client.readStream()) != null) { + view.setTxAreaCaht(inp); + } + } catch (IOException ex) { + System.out.println("Error"); + } + } + } +} + + diff --git a/src/chatGUI/ChatView.form b/src/chatGUI/ChatView.form new file mode 100644 index 0000000..7d02e8d --- /dev/null +++ b/src/chatGUI/ChatView.form @@ -0,0 +1,72 @@ + + +
diff --git a/src/chatGUI/ChatView.java b/src/chatGUI/ChatView.java new file mode 100644 index 0000000..0874cee --- /dev/null +++ b/src/chatGUI/ChatView.java @@ -0,0 +1,128 @@ +/* + * 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 chatGUI; + +import java.awt.event.ActionListener; + +/** + * + * @author lailis + */ +public class ChatView extends javax.swing.JFrame { + + /** + * Creates new form ChatView + */ + public ChatView() { + initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + //