Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,839 changes: 1,420 additions & 1,419 deletions nbproject/build-impl.xml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions nbproject/private/private.properties
Original file line number Diff line number Diff line change
@@ -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
18 changes: 7 additions & 11 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/ANDITYAARIFIANTO/Documents/GitHub/Task_4/src/javaChat/ClientConnection.java</file>
<file>file:/C:/Users/ANDITYAARIFIANTO/Documents/GitHub/Task_4/src/javaChat/ServerConnection.java</file>
<file>file:/C:/Users/ANDITYAARIFIANTO/Documents/GitHub/Task_4/src/javaChat/Connection.java</file>
</group>
</open-files>
</project-private>
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
</open-files>
</project-private>
65 changes: 65 additions & 0 deletions src/ChatGUI/ChatController.java
Original file line number Diff line number Diff line change
@@ -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("");
}
}

}
69 changes: 69 additions & 0 deletions src/ChatGUI/ChatView.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jScrollPane1" pref="380" max="32767" attributes="0"/>
<Component id="TxField" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="242" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="TxField" min="-2" pref="30" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextField" name="TxField">
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="TxArea">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
<Property name="text" type="java.lang.String" value="Input Server IP Address :"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>
95 changes: 95 additions & 0 deletions src/ChatGUI/ChatView.java
Original file line number Diff line number Diff line change
@@ -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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
}// </editor-fold>//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
}
54 changes: 54 additions & 0 deletions src/ConsoleApp/ConnectionThread.java
Original file line number Diff line number Diff line change
@@ -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());
}
}


}
64 changes: 64 additions & 0 deletions src/ConsoleApp/ConsoleApplication.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Loading