diff --git a/Task_4-master/README.md b/Task_4-master/README.md new file mode 100644 index 0000000..903fa5c --- /dev/null +++ b/Task_4-master/README.md @@ -0,0 +1,178 @@ +# Task_4 2017 +Exercise on Inner Class and Threading + + +Buatlah program java untuk chatting antar computer sebagai berikut
+ +## Package javaChat +--- +Package berisi kelas-kelas Socket dan Network Programming + [disediakan] + +## Package consoleApp +--- +Package berisi kelas-kelas model + +### ConnectionThread.java +Buatlah class ConnectionThread.java sebagai berikut + * extends Thread + * import library berikut
+ ![01](https://cloud.githubusercontent.com/assets/13241336/24838003/47eae6d0-1d6a-11e7-9c60-74e646db74de.JPG)
+ * buatlah class sesuai class diagram berikut
+ ![02](https://cloud.githubusercontent.com/assets/13241336/24838004/47efac38-1d6a-11e7-9469-d84bfce698fb.JPG)
+ +#### Constructor + * Constructor throws IOException + * Constructor mengeset attribut client dan menginstansiasi objek Connection dengan input client
+ ![03](https://cloud.githubusercontent.com/assets/13241336/24838006/47f63c6a-1d6a-11e7-848e-7070c0503ec3.JPG)
+ +#### method run() + * Merupakan method yang dijalankan saat thread diaktifkan + * Thread akan aktif setiap ada Client baru yang terhubung ke Server + * Thread akan berhenti ketika Client mengirimkan pesan "quit" + * lakukan proses berikut dalam blok try-catch + * jalankan proses chatting dengan memanggil method startChat(String) dari objek connection
+ ![04](https://cloud.githubusercontent.com/assets/13241336/24838005/47f3b74c-1d6a-11e7-80a9-4625e38a221f.JPG)
+ * tampilkan informasi Client yang terhubung dengan method getClientInformation dari Objek connection
+ ![05](https://cloud.githubusercontent.com/assets/13241336/24838008/481131b4-1d6a-11e7-8f61-50c4c27b8b24.JPG)
+ * lakukan proses loop membaca inputan text dari client dengan memanggil method readStream() dari objek connection selama input readStream masih membaca dan input String bukanlah "quit" + * tampilkan pesan yang diterima dari client, dan kirimkan (broadcast) pesat tersebut ke client yang lain menggunakan method sendToAll() dari objek connection
+ ![06](https://cloud.githubusercontent.com/assets/13241336/24838007/480487de-1d6a-11e7-9802-5b446d56e83c.JPG)
+ * tampilkan pesan kepada semua client jika ada client yang keluar dari chat room, kemudian putuskan koneksi terhadap client tsb dengan memanggil method disconnect() dari object connection
+ ![07](https://cloud.githubusercontent.com/assets/13241336/24838009/4821394c-1d6a-11e7-9404-42bedc403a17.JPG)
+ * tambahkan pesan di blok catch untuk menampilkan pesan error + +### ConsoleApplication.java +Buatlah class ConsoleApplication.java sebagai berikut + * buatlah class sesuai class diagram berikut
+ ![08](https://cloud.githubusercontent.com/assets/13241336/24838010/4826b34a-1d6a-11e7-9e3a-e6d849949100.JPG)
+ * class ReadInput dan WriteOutput merupakan Inner Class + + #### inner class ReadInput + * extends Thread + * method run() + * lakukan proses berikut dalam blok try-catch + * Thread akan membaca input keyboard dari client dengan memanggil method inputString() + * Mengirimkan hasil input keyboard ke server melalui method writeStream() selama input dari client bukanlah kata "quit"
+ ![09](https://cloud.githubusercontent.com/assets/13241336/24838011/482a861e-1d6a-11e7-8fc9-173a14f8e567.JPG)
+ * tambahkan pesan di blok catch untuk menampilkan pesan error + + #### inner class WriteOutput + * extends Thread + * method run() + * lakukan proses berikut dalam blok try-catch + * Thread akan menerima pesan yang dikirimkan dari server melalui method readStream() + * Menampilkan ke layar selama pesan dari server masih ada (bukan null)
+ ![10](https://cloud.githubusercontent.com/assets/13241336/24838012/48306f2a-1d6a-11e7-9a43-f47ee2b98f02.JPG)
+ * tambahkan pesan di blok catch untuk menampilkan pesan error + + #### method startChat() + * lakukan proses berikut dalam blok try-catch + * Instansiasi objek ClientConnection
+ ![11](https://cloud.githubusercontent.com/assets/13241336/24838013/483c890e-1d6a-11e7-98b6-4c301860475b.JPG)
+ * Minta input alamat ip Server menggunakan method inputString() + * Koneksikan ip client ke server dengan memanggil method connect(ip)
+ ![12](https://cloud.githubusercontent.com/assets/13241336/24838014/484be2c8-1d6a-11e7-8692-b8d78bc9278b.JPG)
+ * Instansiasi dan jalankan Thread ReadInput dan WriteInput
+ ![13](https://cloud.githubusercontent.com/assets/13241336/24838015/4857e94c-1d6a-11e7-8dc2-8d4532139dd0.JPG)
+ * tambahkan pesan di blok catch untuk menampilkan pesan error + +## Package chatGUI + --- +Package berisi kelas view GUI dan controller + +### ChatView.java +Buatlah class JFrame ChatView.java dengan tampilan sebagai berikut
+ ![16](https://cloud.githubusercontent.com/assets/13241336/24838018/4866d664-1d6a-11e7-973e-f8d8fce9fd69.JPG)
+ * terdapat sebuah text area (txAreaChat) + * set editable text area = false (uncheck editable) + * tambahkan text "Input Server IP Address : " pada text area
+ ![17](https://cloud.githubusercontent.com/assets/13241336/24838019/4875389e-1d6a-11e7-8eac-c0d8458cec6d.JPG)
+ * terdapat sebuah text field (txFieldChat) + * tambahkan method getTxFieldChat() yang mengembalikan objek text field txFieldChat + * tambahkan method getStringChat() yang mengembalikan String dari text field txFieldChat + * tambahkan method setTxFieldChat(String) yang mengeset String pada text field txFieldChat + * tambahkan method setTxAreaChat(String) yang menambahkan string pada baris baru pada text area txAreaChat
+ ![18](https://cloud.githubusercontent.com/assets/13241336/24838020/48857ff6-1d6a-11e7-85ac-5ec918c3f5de.JPG)
+ * import java.awt.event.ActionListener; + * tambahkan method addListener(ActionListener e) + * tambahkan add listener dengan memanggil method addActionListener pada text field txfieldChat
+ ![19](https://cloud.githubusercontent.com/assets/13241336/24838021/48a8a4a4-1d6a-11e7-9282-e179f4354f66.JPG)
+ +### ChatController.java +Buatlah class JChatController.java sebagai berikut
+ * buatlah class sesuai class diagram berikut
+ ![20](https://cloud.githubusercontent.com/assets/13241336/24838022/48ac72dc-1d6a-11e7-9a64-c667207f5ba3.JPG)
+ * class WriteOutput merupakan Inner Class + * import java.awt.event.ActionListener; + * kelas implements ActionListener + * implementasikan method actionPerformed(ActionEvent ae) + +#### Constructor ChatController + * Constructor menginstansiasi GUI view + * set visible view = true + * set lisener view dengan controller this + * set client = null
+ ![21](https://cloud.githubusercontent.com/assets/13241336/24838023/48af978c-1d6a-11e7-8687-556450c3f166.JPG)
+ +#### inner class WriteOutput + * extends Thread + * method run() + * lakukan proses berikut dalam blok try-catch + * Thread akan menerima pesan yang dikirimkan dari server melalui method readStream() + * Menampilkan pesan ke text area view selama pesan dari server masih ada (bukan null) menggunakan method setTxAreaChat
+ ![23](https://cloud.githubusercontent.com/assets/13241336/24838025/48b71034-1d6a-11e7-8a34-2eba0fd76ae6.JPG)
+ * tambahkan pesan di blok catch untuk menampilkan pesan error + +#### method actionPerformed(ActionEvent ae) + * get Object source action event
+ ![22](https://cloud.githubusercontent.com/assets/13241336/24838024/48b3917a-1d6a-11e7-82be-7034ca4b1dbe.JPG)
+ * cek source action event + * jika event berasal dari text field (tekan tombol enter di text field), cek apakah client sudah terhubung + * jika client masih null + * lakukan proses berikut dalam blok try-catch + * instansiasi ClientConnection baru + * Terima string ip dari user dengan memanggil method getStringChat dari objek view
+ ![24](https://cloud.githubusercontent.com/assets/13241336/24838026/48c684c4-1d6a-11e7-96c1-749c7c99fa9c.JPG)
+ * Instansiasi dan jalankan objek WriteOutput
+ ![25](https://cloud.githubusercontent.com/assets/13241336/24838027/48e2eb8c-1d6a-11e7-87c2-d5edd36bbbb4.JPG)
+ * tambahkan pesan di blok catch untuk menampilkan pesan error + * jika client sudah terbentuk (koneksi sudah terbentuk) + * terima input dari view menggunakan method getStringChat() + * kirimkan hasil input String ke server melalui method writeStream()
+ ![26](https://cloud.githubusercontent.com/assets/13241336/24838028/48e4e428-1d6a-11e7-9dd6-1be75b5816bb.JPG)
+ * hapus isi dari text field pada view menggunakan method setTxFieldChat
+ ![27](https://cloud.githubusercontent.com/assets/13241336/24838029/48e6fd62-1d6a-11e7-8d3c-a72e5ee005ec.JPG)
+ +## Package driver + --- +Package berisi kelas-kelas model + +### DriverServer.java +Buatlah class DriverServer.java sebagai berikut + * kelas memiliki main method (psvm) + * lakukan proses berikut dalam blok try-catch di dalam main method + * Instansiasi objek ServerConnection dan tampilkan informasi server dengan memanggil method getServerInformation()
+ ![14](https://cloud.githubusercontent.com/assets/13241336/24838016/485e7bae-1d6a-11e7-8072-05a72897aa4e.JPG)
+ * Lakukan perulangan untuk menjalankan ConnectionThread setiap server menerima Client baru + * Jalankan thread connection
+ ![15](https://cloud.githubusercontent.com/assets/13241336/24838017/4865aa00-1d6a-11e7-997c-f59cdf225d97.JPG)
+ * tambahkan pesan di blok catch untuk menampilkan pesan error + * Jalankan kelas DriverServer + +### DriverClientConsole.java +Buatlah class DriverClient.java sebagai berikut + * kelas memiliki main method (psvm) + * instansiasi objek ConsoleApplication + * panggil method startChat dari objek ConsoleApplication + * Jalankan kelas DriverClientConsole + * hubungkan dengan IP server + * cobalah aplikasi chat console yang telah dibuat + +### DriverClientGui.java +Buatlah class DriverClientGui.java sebagai berikut + * kelas memiliki main method (psvm) + * instansiasi objek ChatController + * Jalankan kelas DriverClientGui + * hubungkan dengan IP server + * cobalah aplikasi chat Gui yang telah dibuat diff --git a/Task_4-master/assets/01.JPG b/Task_4-master/assets/01.JPG new file mode 100644 index 0000000..1fedd52 Binary files /dev/null and b/Task_4-master/assets/01.JPG differ diff --git a/Task_4-master/assets/02.JPG b/Task_4-master/assets/02.JPG new file mode 100644 index 0000000..0d5a0eb Binary files /dev/null and b/Task_4-master/assets/02.JPG differ diff --git a/Task_4-master/assets/03.JPG b/Task_4-master/assets/03.JPG new file mode 100644 index 0000000..6e3924d Binary files /dev/null and b/Task_4-master/assets/03.JPG differ diff --git a/Task_4-master/assets/04.JPG b/Task_4-master/assets/04.JPG new file mode 100644 index 0000000..b1c2dd5 Binary files /dev/null and b/Task_4-master/assets/04.JPG differ diff --git a/Task_4-master/assets/05.JPG b/Task_4-master/assets/05.JPG new file mode 100644 index 0000000..fbb91eb Binary files /dev/null and b/Task_4-master/assets/05.JPG differ diff --git a/Task_4-master/assets/06.JPG b/Task_4-master/assets/06.JPG new file mode 100644 index 0000000..e8a6a42 Binary files /dev/null and b/Task_4-master/assets/06.JPG differ diff --git a/Task_4-master/assets/07.JPG b/Task_4-master/assets/07.JPG new file mode 100644 index 0000000..7090e7c Binary files /dev/null and b/Task_4-master/assets/07.JPG differ diff --git a/Task_4-master/assets/08.JPG b/Task_4-master/assets/08.JPG new file mode 100644 index 0000000..9cfb164 Binary files /dev/null and b/Task_4-master/assets/08.JPG differ diff --git a/Task_4-master/assets/09.JPG b/Task_4-master/assets/09.JPG new file mode 100644 index 0000000..e1c77c3 Binary files /dev/null and b/Task_4-master/assets/09.JPG differ diff --git a/Task_4-master/assets/10.JPG b/Task_4-master/assets/10.JPG new file mode 100644 index 0000000..3cfd80a Binary files /dev/null and b/Task_4-master/assets/10.JPG differ diff --git a/Task_4-master/assets/11.JPG b/Task_4-master/assets/11.JPG new file mode 100644 index 0000000..56b00a0 Binary files /dev/null and b/Task_4-master/assets/11.JPG differ diff --git a/Task_4-master/assets/12.JPG b/Task_4-master/assets/12.JPG new file mode 100644 index 0000000..65a66a7 Binary files /dev/null and b/Task_4-master/assets/12.JPG differ diff --git a/Task_4-master/assets/13.JPG b/Task_4-master/assets/13.JPG new file mode 100644 index 0000000..f0b0e98 Binary files /dev/null and b/Task_4-master/assets/13.JPG differ diff --git a/Task_4-master/assets/14.JPG b/Task_4-master/assets/14.JPG new file mode 100644 index 0000000..731c564 Binary files /dev/null and b/Task_4-master/assets/14.JPG differ diff --git a/Task_4-master/assets/15.JPG b/Task_4-master/assets/15.JPG new file mode 100644 index 0000000..4e171c8 Binary files /dev/null and b/Task_4-master/assets/15.JPG differ diff --git a/Task_4-master/assets/16.JPG b/Task_4-master/assets/16.JPG new file mode 100644 index 0000000..a674f72 Binary files /dev/null and b/Task_4-master/assets/16.JPG differ diff --git a/Task_4-master/assets/17.JPG b/Task_4-master/assets/17.JPG new file mode 100644 index 0000000..a4227f6 Binary files /dev/null and b/Task_4-master/assets/17.JPG differ diff --git a/Task_4-master/assets/18.JPG b/Task_4-master/assets/18.JPG new file mode 100644 index 0000000..023e1c7 Binary files /dev/null and b/Task_4-master/assets/18.JPG differ diff --git a/Task_4-master/assets/19.JPG b/Task_4-master/assets/19.JPG new file mode 100644 index 0000000..8a43b62 Binary files /dev/null and b/Task_4-master/assets/19.JPG differ diff --git a/Task_4-master/assets/20.JPG b/Task_4-master/assets/20.JPG new file mode 100644 index 0000000..cadb692 Binary files /dev/null and b/Task_4-master/assets/20.JPG differ diff --git a/Task_4-master/assets/21.JPG b/Task_4-master/assets/21.JPG new file mode 100644 index 0000000..973b4bb Binary files /dev/null and b/Task_4-master/assets/21.JPG differ diff --git a/Task_4-master/assets/22.JPG b/Task_4-master/assets/22.JPG new file mode 100644 index 0000000..da7730e Binary files /dev/null and b/Task_4-master/assets/22.JPG differ diff --git a/Task_4-master/assets/23.JPG b/Task_4-master/assets/23.JPG new file mode 100644 index 0000000..3e60b3b Binary files /dev/null and b/Task_4-master/assets/23.JPG differ diff --git a/Task_4-master/assets/24.JPG b/Task_4-master/assets/24.JPG new file mode 100644 index 0000000..f59614d Binary files /dev/null and b/Task_4-master/assets/24.JPG differ diff --git a/Task_4-master/assets/25.JPG b/Task_4-master/assets/25.JPG new file mode 100644 index 0000000..f9496f8 Binary files /dev/null and b/Task_4-master/assets/25.JPG differ diff --git a/Task_4-master/assets/26.JPG b/Task_4-master/assets/26.JPG new file mode 100644 index 0000000..0a9ad9a Binary files /dev/null and b/Task_4-master/assets/26.JPG differ diff --git a/Task_4-master/assets/27.JPG b/Task_4-master/assets/27.JPG new file mode 100644 index 0000000..d0fb363 Binary files /dev/null and b/Task_4-master/assets/27.JPG differ diff --git a/Task_4-master/build.xml b/Task_4-master/build.xml new file mode 100644 index 0000000..03f4ad0 --- /dev/null +++ b/Task_4-master/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Task_4. + + + diff --git a/Task_4-master/manifest.mf b/Task_4-master/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Task_4-master/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Task_4-master/nbproject/build-impl.xml b/Task_4-master/nbproject/build-impl.xml new file mode 100644 index 0000000..4abce43 --- /dev/null +++ b/Task_4-master/nbproject/build-impl.xml @@ -0,0 +1,1419 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Task_4-master/nbproject/genfiles.properties b/Task_4-master/nbproject/genfiles.properties new file mode 100644 index 0000000..cb2d623 --- /dev/null +++ b/Task_4-master/nbproject/genfiles.properties @@ -0,0 +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 diff --git a/Task_4-master/nbproject/private/private.properties b/Task_4-master/nbproject/private/private.properties new file mode 100644 index 0000000..d689f61 --- /dev/null +++ b/Task_4-master/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=/home/faza/.netbeans/8.1/build.properties diff --git a/Task_4-master/nbproject/private/private.xml b/Task_4-master/nbproject/private/private.xml new file mode 100644 index 0000000..6807a2b --- /dev/null +++ b/Task_4-master/nbproject/private/private.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Task_4-master/nbproject/project.properties b/Task_4-master/nbproject/project.properties new file mode 100644 index 0000000..de16b77 --- /dev/null +++ b/Task_4-master/nbproject/project.properties @@ -0,0 +1,73 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Task_4.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=task.Task +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Task_4-master/nbproject/project.xml b/Task_4-master/nbproject/project.xml new file mode 100644 index 0000000..07d3ecf --- /dev/null +++ b/Task_4-master/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Task_4 + + + + + + + + + diff --git a/Task_4-master/src/ConsoleApp/ConsoleApplication.java b/Task_4-master/src/ConsoleApp/ConsoleApplication.java new file mode 100644 index 0000000..57574a7 --- /dev/null +++ b/Task_4-master/src/ConsoleApp/ConsoleApplication.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 ConsoleApp; + +/** + * + * @author faza + */ +import java.io.IOException; +import javaChat.ClientConnection; +import java.util.logging.Level; +import java.util.logging.Logger; + +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 E) { + 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 E) { + System.out.println("Error"); + } + } + } + + 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 (IOException E) { + System.out.println("Error"); + } + } +} diff --git a/Task_4-master/src/ConsoleApp/ConsoleThread.java b/Task_4-master/src/ConsoleApp/ConsoleThread.java new file mode 100644 index 0000000..2e88d4c --- /dev/null +++ b/Task_4-master/src/ConsoleApp/ConsoleThread.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; + +/** + * + * @author faza + */ +import java.io.IOException; +import java.net.Socket; +import javaChat.Connection; + +public class ConsoleThread { + private Socket client; + private Connection connection; + + public ConsoleThread(Socket newClient) throws IOException { + this.client = newClient; + connection = new Connection(client); + } + + public void run() throws IOException { + 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 the Char Room"; + System.out.println(message); + connection.sendToAll(message); + connection.disconnect(); + + } catch (IOException E) { + System.out.println("Error"); + } + } +} diff --git a/Task_4-master/src/Driver/DriverClientConsole.java b/Task_4-master/src/Driver/DriverClientConsole.java new file mode 100644 index 0000000..0c49d88 --- /dev/null +++ b/Task_4-master/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; + +/** + * + * @author faza + */ +public class DriverClientConsole { + public static void main(String[] args) { + ConsoleApplication consoleA = new ConsoleApplication(); + consoleA.startChat(); + } +} diff --git a/Task_4-master/src/Driver/DriverClientGui.java b/Task_4-master/src/Driver/DriverClientGui.java new file mode 100644 index 0000000..882ccba --- /dev/null +++ b/Task_4-master/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.JChatController; + +/** + * + * @author faza + */ +public class DriverClientGui { + public static void main(String[] args) { + JChatController Jchat = new JChatController(); + } +} diff --git a/Task_4-master/src/Driver/DriverServer.java b/Task_4-master/src/Driver/DriverServer.java new file mode 100644 index 0000000..a69892e --- /dev/null +++ b/Task_4-master/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 java.io.IOException; +import javaChat.ServerConnection; +import ConsoleApp.ConsoleThread; + +/** + * + * @author faza + */ +public class DriverServer { + public static void main(String[] args) { + try { + ServerConnection serverc = new ServerConnection(); + System.out.println("Server Information"); + System.out.println(serverc.getServerInformation()); + while (true) { + ConsoleThread connectionT = new ConsoleThread(serverc.getClient()); + connectionT.run(); + + } + } catch (IOException E) { + System.out.println("Error"); + } + } +} diff --git a/Task_4-master/src/chatGUI/ChatController.java b/Task_4-master/src/chatGUI/ChatController.java new file mode 100644 index 0000000..1962008 --- /dev/null +++ b/Task_4-master/src/chatGUI/ChatController.java @@ -0,0 +1,14 @@ +/* + * 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; + +/** + * + * @author faza + */ +public class ChatController { + +} diff --git a/Task_4-master/src/chatGUI/ChatView.form b/Task_4-master/src/chatGUI/ChatView.form new file mode 100644 index 0000000..3a35573 --- /dev/null +++ b/Task_4-master/src/chatGUI/ChatView.form @@ -0,0 +1,69 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Task_4-master/src/chatGUI/ChatView.java b/Task_4-master/src/chatGUI/ChatView.java new file mode 100644 index 0000000..1cd04e8 --- /dev/null +++ b/Task_4-master/src/chatGUI/ChatView.java @@ -0,0 +1,129 @@ +/* + * 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 Farid Kiftirul Aziz + */ +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() { + + jScrollPane2 = 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 :"); + jScrollPane2.setViewportView(txAreaChat); + + 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(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) + .addComponent(txFieldChat, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(txFieldChat) + .addGap(18, 18, 18)) + ); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ +// public static void main(String args[]) { +// /* Set the Nimbus 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 +// */ +// try { +// for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { +// if ("Nimbus".equals(info.getName())) { +// javax.swing.UIManager.setLookAndFeel(info.getClassName()); +// break; +// } +// } +// } catch (ClassNotFoundException ex) { +// java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); +// } catch (InstantiationException ex) { +// java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); +// } catch (IllegalAccessException ex) { +// java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); +// } catch (javax.swing.UnsupportedLookAndFeelException ex) { +// java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); +// } +// // +// +// /* Create and display the form */ +// java.awt.EventQueue.invokeLater(new Runnable() { +// public void run() { +// new ChatView().setVisible(true); +// } +// }); +// } + 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 e) { + txFieldChat.addActionListener(e); + } + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextArea txAreaChat; + private javax.swing.JTextField txFieldChat; + // End of variables declaration//GEN-END:variables + +} diff --git a/Task_4-master/src/chatGUI/JChatController.java b/Task_4-master/src/chatGUI/JChatController.java new file mode 100644 index 0000000..fd84471 --- /dev/null +++ b/Task_4-master/src/chatGUI/JChatController.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.text.View; + +/** + * + * @author faza + */ +public class JChatController implements ActionListener { + + private ChatView view; + private ClientConnection client; + + public JChatController() { + view = new ChatView(); + view.setVisible(true); + view.addListener(this); + client = null; + } + + public class WriteOutput extends Thread { + + @Override + public void run() { + String inputan; + try { + while ((inputan = client.readStream()) != null) { + view.setTxAreaChat(inputan); + } + } catch (IOException E) { + System.out.println("Error"); + } + } + } + + @Override + public void actionPerformed(ActionEvent ae) { + Object source = ae.getSource(); + + if (source.equals(view.getTxFieldChat())) { + if (client == null) { + try { + client = new ClientConnection(); + String ip = view.getStringChat(); + client.connect(ip); + WriteOutput w = new WriteOutput(); + w.start(); + } catch (IOException E) { + System.out.println("Error"); + } + } else { + String input = view.getStringChat(); + client.writeStream(input); + view.setTxFieldChat(""); + } + } + } +} diff --git a/Task_4-master/src/javaChat/ClientConnection.java b/Task_4-master/src/javaChat/ClientConnection.java new file mode 100644 index 0000000..e79488e --- /dev/null +++ b/Task_4-master/src/javaChat/ClientConnection.java @@ -0,0 +1,56 @@ +/* + * 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 javaChat; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; + +/** + * + * @author dee + */ +public class ClientConnection { + + private BufferedReader keyBoard; + private BufferedReader inputStream; + private PrintWriter outputStream; + final private int PORT = 4444; + private Socket client; + + public ClientConnection() { + keyBoard = new BufferedReader(new InputStreamReader(System.in)); + } + + public void connect(String ip) throws IOException { + client = new Socket(ip, PORT); + inputStream = new BufferedReader(new InputStreamReader(client.getInputStream())); + outputStream = new PrintWriter(client.getOutputStream(), true); + } + + public void disconnect() throws IOException { + keyBoard.close(); + inputStream.close(); + outputStream.close(); + client.close(); + } + + public String inputString() throws IOException { + return keyBoard.readLine(); + } + + public String readStream() throws IOException { + return inputStream.readLine(); + } + + public void writeStream(String text) { + outputStream.println(text); + outputStream.flush(); + } + +} diff --git a/Task_4-master/src/javaChat/Connection.java b/Task_4-master/src/javaChat/Connection.java new file mode 100644 index 0000000..b049aaa --- /dev/null +++ b/Task_4-master/src/javaChat/Connection.java @@ -0,0 +1,108 @@ +/* + * 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 javaChat; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.Socket; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author dee + */ +public class Connection { + + private Socket client; + private String ipClient = ""; + private BufferedReader inputStream; + private DataOutputStream outputStream; + private InetAddress destAddress; + private static ArrayList list = new ArrayList<>(); +// private static Map users = new HashMap<>(); + +// public Connection(Socket client, String username) throws IOException { +// this.client = client; +// inputStream = new BufferedReader(new InputStreamReader(client.getInputStream())); +//// outputStream = new DataOutputStream(client.getOutputStream()); +// users.put(username, new DataOutputStream(client.getOutputStream())); +// +// destAddress = this.client.getInetAddress(); +// byte ipAddress[] = destAddress.getAddress(); +// for (int i = 0; i < ipAddress.length; ++i) { +// ipClient += String.valueOf((ipAddress[i] + 256) % 256) + "."; +// } +// } + + public Connection(Socket client) throws IOException { + this.client = client; + list.add(client); + inputStream = new BufferedReader(new InputStreamReader(client.getInputStream())); + outputStream = new DataOutputStream(client.getOutputStream()); + + destAddress = this.client.getInetAddress(); + byte ipAddress[] = destAddress.getAddress(); + for (int i = 0; i < ipAddress.length; ++i) { + ipClient += String.valueOf((ipAddress[i] + 256) % 256) + "."; + } + } + + public void disconnect() throws IOException { + list.remove(client); + inputStream.close(); + outputStream.close(); + client.close(); + } + + public String readStream() throws IOException { + return inputStream.readLine(); + } + + public void startChat(String text) throws IOException { + outputStream.writeBytes(text + "\n"); + } + + public void writeStream(String text) throws IOException { + outputStream.writeBytes(text + "\n"); + outputStream.flush(); + } + + public void sendToAll(String s) { + for (Socket c : list) { + try { + if (c != null) { + DataOutputStream d = new DataOutputStream(c.getOutputStream()); + d.writeBytes(s + "\n"); + d.flush(); + } + } catch (Exception e) { + System.out.println("error when send to all"); + } + } + } + + public String getIpClient() { + return ipClient; + } + + public int getPortClient() { + return client.getPort(); + } + + public String getClientInformation() { + + String s = " Host name is " + destAddress.getHostName() + + "\n IP address is " + this.ipClient + + "\n Port number is " + getPortClient(); + return s; + } + +} diff --git a/Task_4-master/src/javaChat/ServerConnection.java b/Task_4-master/src/javaChat/ServerConnection.java new file mode 100644 index 0000000..8a1902e --- /dev/null +++ b/Task_4-master/src/javaChat/ServerConnection.java @@ -0,0 +1,45 @@ +/* + * 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 javaChat; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * + * @author dee + */ +public class ServerConnection { + + private ServerSocket serverSocket; + private InetAddress localAddress; + private String host; + private String ipServer = ""; + + public ServerConnection() throws IOException { + serverSocket = new ServerSocket(4444); + localAddress = InetAddress.getLocalHost(); + host = localAddress.getHostName(); + byte ipAddress[] = localAddress.getAddress(); + for (int i = 0; i < ipAddress.length; ++i) { + ipServer += String.valueOf((ipAddress[i] + 256) % 256) + "."; + } + } + + public Socket getClient() throws IOException { + return serverSocket.accept(); + } + + public String getServerInformation() { + String s = " Host name is " + host + + "\n IP address is " + ipServer + + "\n Port number " + 4444; + return s; + } + +}