From dc69e4d8afb5eb42aa2cb20f1aef8fe79f892d38 Mon Sep 17 00:00:00 2001 From: Herica Bunga M Date: Tue, 2 May 2017 09:30:39 +0700 Subject: [PATCH 1/2] update --- src/Driver/DriverClientConsole.java | 20 ++++++ src/Driver/DriverClientGui.java | 18 +++++ src/Driver/DriverServer.java | 31 ++++++++ src/chatGUI/ChatController.java | 67 +++++++++++++++++ src/chatGUI/ChatView.form | 72 +++++++++++++++++++ src/chatGUI/ChatView.java | 99 ++++++++++++++++++++++++++ src/consoleApp/ConnectionThread.java | 49 +++++++++++++ src/consoleApp/ConsoleApplication.java | 65 +++++++++++++++++ 8 files changed, 421 insertions(+) create mode 100644 src/Driver/DriverClientConsole.java create mode 100644 src/Driver/DriverClientGui.java create mode 100644 src/Driver/DriverServer.java create mode 100644 src/chatGUI/ChatController.java create mode 100644 src/chatGUI/ChatView.form create mode 100644 src/chatGUI/ChatView.java create mode 100644 src/consoleApp/ConnectionThread.java create mode 100644 src/consoleApp/ConsoleApplication.java diff --git a/src/Driver/DriverClientConsole.java b/src/Driver/DriverClientConsole.java new file mode 100644 index 0000000..efe8721 --- /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 Herica Bunga M (1301154572) + */ +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..b9b47bc --- /dev/null +++ b/src/Driver/DriverClientGui.java @@ -0,0 +1,18 @@ +/* + * 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 USER + */ +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..aa76bac --- /dev/null +++ b/src/Driver/DriverServer.java @@ -0,0 +1,31 @@ +/* + * 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 Herica Bunga M (1301154572) + */ +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..99d681a --- /dev/null +++ b/src/chatGUI/ChatController.java @@ -0,0 +1,67 @@ +/* + * 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.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import javaChat.ClientConnection; +import javax.swing.JOptionPane; + +/** + * + * @author Herica Bunga M (1301154572) + */ +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 ae) { + Object source = ae.getSource(); + if (source.equals(view.getTxFieldChat())) { + if (client == null){ + try { + client = new ClientConnection(); + view.setTxAreaChat(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.setTxFieldChat(""); + } + } + } + + public class WriteOutput extends Thread { + + public void run() { + try { + String inp; + while ((inp = client.readStream()) != null) { + view.setTxAreaChat(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..da806ae --- /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..bfa2935 --- /dev/null +++ b/src/chatGUI/ChatView.java @@ -0,0 +1,99 @@ +/* + * 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 Herica Bunga M (1301154572) + */ +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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + txAreaChat = new javax.swing.JTextArea(); + txFieldChat = new javax.swing.JTextField(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + txAreaChat.setEditable(false); + txAreaChat.setColumns(20); + txAreaChat.setRows(5); + txAreaChat.setText("Input Server IP Address : "); + jScrollPane1.setViewportView(txAreaChat); + + txFieldChat.setEditable(false); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) + .addComponent(txFieldChat)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(txFieldChat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + + public void setTxAreaChat(String Message) { + txAreaChat.append(Message + "\n"); + } + + public Object getTxFieldChat() { + return txFieldChat; + } + + public String getStringChat() { + return txFieldChat.getText(); + } + + public void setTxFieldChat(String Message) { + this.txFieldChat.setText(Message); + } + + public void addListener (ActionListener ae){ + txFieldChat.addActionListener(ae); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea txAreaChat; + private javax.swing.JTextField txFieldChat; + // End of variables declaration//GEN-END:variables +} diff --git a/src/consoleApp/ConnectionThread.java b/src/consoleApp/ConnectionThread.java new file mode 100644 index 0000000..bb40940 --- /dev/null +++ b/src/consoleApp/ConnectionThread.java @@ -0,0 +1,49 @@ +/* + * 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 javaChat.Connection; + +/** + * + * @author Herica Bunga M (1301154572) + */ +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("------Start 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 e) { + System.out.println("Error"); + } + } +} + diff --git a/src/consoleApp/ConsoleApplication.java b/src/consoleApp/ConsoleApplication.java new file mode 100644 index 0000000..6e20654 --- /dev/null +++ b/src/consoleApp/ConsoleApplication.java @@ -0,0 +1,65 @@ +/* + * 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 javaChat.ClientConnection; + +/** + * + * @author Herica Bunga M (1301154572) + */ +public class ConsoleApplication { + private ClientConnection client; + + public class ReadInput extends Thread{ + @Override + 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 { + @Override + 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(); + } +} + From b388d9039e63b9a04b051fd078bc7d0fad42c76c Mon Sep 17 00:00:00 2001 From: Herica Bunga M Date: Tue, 2 May 2017 09:32:04 +0700 Subject: [PATCH 2/2] update --- nbproject/build-impl.xml | 2839 +++++++++++++------------- nbproject/genfiles.properties | 16 +- nbproject/private/private.properties | 4 +- 3 files changed, 1430 insertions(+), 1429 deletions(-) diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 4abce43..f124f4f 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1,1419 +1,1420 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index cb2d623..8121f30 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=6d39ee20 -build.xml.script.CRC32=528642be -build.xml.stylesheet.CRC32=8064a381@1.75.1.48 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=6d39ee20 -nbproject/build-impl.xml.script.CRC32=681df6e3 -nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 +build.xml.data.CRC32=6d39ee20 +build.xml.script.CRC32=528642be +build.xml.stylesheet.CRC32=8064a381@1.75.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=6d39ee20 +nbproject/build-impl.xml.script.CRC32=5c486f47 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 1b6c36a..805d58a 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\\USER\\AppData\\Roaming\\NetBeans\\8.2\\build.properties