From 7d25b6ab5cee5300b015c4b75034641aca1470d2 Mon Sep 17 00:00:00 2001 From: MRPanda Date: Sun, 21 May 2017 16:39:35 +0700 Subject: [PATCH] PBO_1301154404_Task4_ADF --- nbproject/build-impl.xml | 2839 ++++++++++++------------ nbproject/genfiles.properties | 16 +- nbproject/private/private.properties | 4 +- nbproject/private/private.xml | 18 +- src/ChatGUI/ChatController.java | 65 + src/ChatGUI/ChatView.form | 69 + src/ChatGUI/ChatView.java | 95 + src/ConsoleApp/ConnectionThread.java | 54 + src/ConsoleApp/ConsoleApplication.java | 64 + src/Driver/DriverClientConsole.java | 19 + src/Driver/DriverClientGUI.java | 18 + src/Driver/DriverServer.java | 28 + 12 files changed, 1849 insertions(+), 1440 deletions(-) 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 create mode 100644 src/Driver/DriverClientConsole.java create mode 100644 src/Driver/DriverClientGUI.java create mode 100644 src/Driver/DriverServer.java 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..9afdc88 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\\Asus\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 52e3867..284eeec 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -1,11 +1,7 @@ - - - - - - file:/C:/Users/ANDITYAARIFIANTO/Documents/GitHub/Task_4/src/javaChat/ClientConnection.java - file:/C:/Users/ANDITYAARIFIANTO/Documents/GitHub/Task_4/src/javaChat/ServerConnection.java - file:/C:/Users/ANDITYAARIFIANTO/Documents/GitHub/Task_4/src/javaChat/Connection.java - - - + + + + + + + diff --git a/src/ChatGUI/ChatController.java b/src/ChatGUI/ChatController.java new file mode 100644 index 0000000..01d09f8 --- /dev/null +++ b/src/ChatGUI/ChatController.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 ChatGUI; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javaChat.ClientConnection; + +/** + * + * @author Asus + */ +public class ChatController implements ActionListener{ + private ChatView view; + private ClientConnection client = null; + + public ChatController(){ + view = new ChatView(); + view.setVisible(true); + view.addActionListener(this); + client = null; + } + + public class WriteOutput extends Thread{ + @Override + public void run(){ + try{ + String inputan; + while((inputan = client.readStream()) != null){ + view.setTxAreaChat(inputan); + } + + }catch(Exception e){ + System.out.println("Error : " + e.getMessage()); + } + } + } + + @Override + public void actionPerformed(ActionEvent ae) { + Object source = ae.getSource(); + if(source == view.getTxFieldChat()){ + if(client == null){ + try{ + String ip = view.getStringChat(); + client.connect(ip); + + WriteOutput w = new WriteOutput(); + w.start(); + }catch(Exception e){ + System.out.println("Error : " + e.getMessage()); + } + } + else{ + String input = view.getStringChat(); + client.writeStream(input); + } + view.setTxField(""); + } + } + +} diff --git a/src/ChatGUI/ChatView.form b/src/ChatGUI/ChatView.form new file mode 100644 index 0000000..cb5059e --- /dev/null +++ b/src/ChatGUI/ChatView.form @@ -0,0 +1,69 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ChatGUI/ChatView.java b/src/ChatGUI/ChatView.java new file mode 100644 index 0000000..cabf6cc --- /dev/null +++ b/src/ChatGUI/ChatView.java @@ -0,0 +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 ChatGUI; + +import java.awt.event.ActionListener; +import javax.swing.JTextArea; + +/** + * + * @author Asus + */ +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() { + + TxField = new javax.swing.JTextField(); + jScrollPane1 = new javax.swing.JScrollPane(); + TxArea = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + TxArea.setEditable(false); + TxArea.setColumns(20); + TxArea.setRows(5); + TxArea.setText("Input Server IP Address :"); + jScrollPane1.setViewportView(TxArea); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) + .addComponent(TxField)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(TxField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + public void setTxAreaChat(String message) { + TxArea.append(message + "\n"); + } + + public Object getTxFieldChat() { + return TxField; + } + + public String getStringChat(){ + return TxField.getText(); + } + + public void setTxField(String message) { + this.TxField.setText(message); + } + + public void addActionListener(ActionListener al){ + TxField.addActionListener(al); + } + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTextArea TxArea; + private javax.swing.JTextField TxField; + private javax.swing.JScrollPane jScrollPane1; + // 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..66bcda3 --- /dev/null +++ b/src/ConsoleApp/ConnectionThread.java @@ -0,0 +1,54 @@ +/* + * 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 Asus + */ +public class ConnectionThread extends Thread { + private Socket client; + private Connection connection; + + public ConnectionThread(Socket newClient) throws IOException { + this.client = newClient; + connection = new Connection(client); + } + + @Override + public void run(){ + try{ + connection.startChat("start a 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 the chat room"; + System.out.println(message); + connection.sendToAll(message); + connection.disconnect(); + + }catch(Exception e){ + System.out.println("Error : " + e.getMessage()); + } + } + + +} diff --git a/src/ConsoleApp/ConsoleApplication.java b/src/ConsoleApp/ConsoleApplication.java new file mode 100644 index 0000000..627c2c6 --- /dev/null +++ b/src/ConsoleApp/ConsoleApplication.java @@ -0,0 +1,64 @@ +/* + * 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 javaChat.ClientConnection; + +/** + * + * @author Asus + */ +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(); + }while(!inputKeyboard.equals("quit")); + client.disconnect(); + }catch(Exception e){ + System.out.println("Error : " + e.getMessage()); + } + } + } + + 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(Exception e){ + System.out.println("Error : " + e.getMessage()); + } + } + } + + public void startChat(){ + try{ + client = new ClientConnection(); + System.out.println("input server IP : "); + String ip = client.inputString(); + client.connect(ip); + + ReadInput in = new ReadInput(); + WriteOutput out = new WriteOutput(); + in.start(); + out.start(); + + }catch(Exception e){ + System.out.println("Error : " + e.getMessage()); + } + } +} diff --git a/src/Driver/DriverClientConsole.java b/src/Driver/DriverClientConsole.java new file mode 100644 index 0000000..81c2809 --- /dev/null +++ b/src/Driver/DriverClientConsole.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 ConsoleApp.ConsoleApplication; +import static java.lang.System.console; + +/** + * + * @author Asus + */ +public class DriverClientConsole { + public static void main(String[] args) { + ConsoleApplication capp = new ConsoleApplication(); + } +} diff --git a/src/Driver/DriverClientGUI.java b/src/Driver/DriverClientGUI.java new file mode 100644 index 0000000..ba3631c --- /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 Asus + */ +public class DriverClientGUI { + public static void main(String[] args) { + ChatController ccon = new ChatController(); + } +} diff --git a/src/Driver/DriverServer.java b/src/Driver/DriverServer.java new file mode 100644 index 0000000..591789d --- /dev/null +++ b/src/Driver/DriverServer.java @@ -0,0 +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 Driver; + +import ConsoleApp.ConnectionThread; +import javaChat.ServerConnection; + +/** + * + * @author Asus + */ +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()); + } + }catch(Exception e){ + System.out.println("Error : " + e.getMessage()); + } + } +}