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
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\\Ncisl\\AppData\\Roaming\\NetBeans\\8.1\\build.properties
53 changes: 53 additions & 0 deletions src/ConsoleApp/ConnectionThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package ConsoleApp;


import java.io.IOException;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javaChat.Connection;



/**
*
* @author lailis
*/
public class ConnectionThread {
private Socket client;
private Connection connection;

public ConnectionThread (Socket newClient ) throws IOException{
this.client = newClient;
connection = new Connection(client);
}

public void run () {
try {
connection.startChat("Strat the Chat-----");
System.out.println("-----------");
System.out.println("new client connected");
System.out.println("client information : ");
System.out.println(connection.getClientInformation());
String inputan;
String message;
while ((inputan = connection.readStream())!= null && !inputan.equals("quit")){
message = "Client " + connection.getIpClient() + "said : " + inputan;
System.out.println(message);
connection.sendToAll(message);
}
message = "Client from IP : " + connection.getIpClient() + "Quit from chat room ";
System.out.println(message);
connection.sendToAll(message);
connection.disconnect();
} catch (IOException ex) { System.out.println("ERROR");
}
}
}

63 changes: 63 additions & 0 deletions src/ConsoleApp/ConsoleApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ConsoleApp;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javaChat.ClientConnection;
/**
*
* @author lailis
*/
public class ConsoleApplication {
private ClientConnection client;

public class ReadInput extends Thread{
public void run (){
try {
String inputKeyboard;
do {
System.out.println(">> ");
inputKeyboard = client.inputString();
client.writeStream(inputKeyboard);
} while (! inputKeyboard.equals("quit"));
client.disconnect();
} catch (IOException ex) {
System.out.println("Error");
}
}
}

public class WriteOutput extends Thread{
public void run (){
try {
String inputan;
while ((inputan = client.readStream()) != null){
System.out.println(inputan);
System.out.println(">> ");
}
} catch (IOException ex) {
System.out.println("Error");
}
}
}

public void startChat() {
try {
client = new ClientConnection();
System.out.println("input server IP : ");
String ip = client.inputString();
client.connect(ip);
} catch (IOException ex) {
System.out.println("ERROR");
}
ReadInput in = new ReadInput();
WriteOutput out = new WriteOutput();
in.start();
out.start();
}
}

20 changes: 20 additions & 0 deletions src/Driver/DriverClientConsole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Driver;

import ConsoleApp.ConsoleApplication;

/**
*
* @author lailis
*/
public class DriverClientConsole {
public static void main(String[] args) {
ConsoleApplication app = new ConsoleApplication();
app.startChat();
}
}

19 changes: 19 additions & 0 deletions src/Driver/DriverClientGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Driver;

import chatGUI.ChatController;

/**
*
* @author lailis
*/
public class DriverClientGUI {
public static void main(String[] args) {
new ChatController();
}
}

33 changes: 33 additions & 0 deletions src/Driver/DriverServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Driver;

import ConsoleApp.ConnectionThread;
import java.io.IOException;
import javaChat.ServerConnection;

/**
*
* @author lailis
*
*/
public class DriverServer {
public static void main(String[] args) {
try {
ServerConnection server = new ServerConnection();
System.out.println("Server Information");
System.out.println(server.getServerInformation());
while (true){
ConnectionThread connection = new ConnectionThread(server.getClient());
connection.run();
}
} catch (IOException ex) {
System.out.println("Error");
}
}
}


69 changes: 69 additions & 0 deletions src/chatGUI/ChatController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatGUI;

import ConsoleApp.ConsoleApplication.WriteOutput;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javaChat.ClientConnection;
import javax.swing.JOptionPane;

/**
*
* @author lailis
*/
public class ChatController implements ActionListener {
private ChatView view;
private ClientConnection client;

public ChatController() {
view = new ChatView();
view.setVisible(true);
view.addListener(this);
client = null;
}

@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source.equals(view.getTextField())){
if (client == null){
try {
client = new ClientConnection();
view.setTxAreaCaht(view.getStringChat());
String ip = view.getStringChat();
client.connect(ip);
WriteOutput w = new WriteOutput();
w.start();
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Error");
}
}
else {
String input = view.getStringChat();
client.writeStream(input);
view.setTextFieldChat("");
}
}
}

public class WriteOutput extends Thread {

public void run() {
try {
String inp;
while ((inp = client.readStream()) != null) {
view.setTxAreaCaht(inp);
}
} catch (IOException ex) {
System.out.println("Error");
}
}
}
}


72 changes: 72 additions & 0 deletions src/chatGUI/ChatView.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" pref="380" max="32767" attributes="0"/>
<Component id="txFieldChat" 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="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="202" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="txFieldChat" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<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="txAreaChat">
<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>
<Component class="javax.swing.JTextField" name="txFieldChat">
<Properties>
<Property name="text" type="java.lang.String" value="jTextField1"/>
</Properties>
</Component>
</SubComponents>
</Form>
Loading