Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hendrik Christian _ 1301150021 #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
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
[email protected]
# 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
[email protected]
# 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\\Christian Janifer\\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>
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="txFieldChat" alignment="1" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="380" 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 min="-2" pref="16" max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="207" max="-2" attributes="0"/>
<EmptySpace 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">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txFieldChatActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
134 changes: 134 additions & 0 deletions src/chatGUI/ChatView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package chatGUI;

import java.awt.event.ActionListener;

/**
*
* @author Christian Janifer
*/
public class ChatView extends javax.swing.JFrame {

/**
* Creates new form JFrameChatView
*/
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() {

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.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txFieldChatActionPerformed(evt);
}
});

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(txFieldChat, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txFieldChat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void txFieldChatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txFieldChatActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txFieldChatActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* 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);
}
//</editor-fold>
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ChatView().setVisible(true);
}
});
}

// 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

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);
}
}
61 changes: 61 additions & 0 deletions src/chatGUI/JChatController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package chatGUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javaChat.ClientConnection;
import java.io.IOException;
import javax.swing.text.View;

/**
*
* @author Christian Janifer
*/
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{

public void run(){
String inputan;
try {
while((inputan = client.readStream()) != null){
view.setTxAreaChat(inputan);
}
} catch (Exception e) {
System.out.println("Error");
}
}
}

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 (Exception e) {
System.out.println("Error");
}
}else{
String input = view.getStringChat();
client.writeStream(input);
view.setTxFieldChat("");
}
}
}
}
45 changes: 45 additions & 0 deletions src/consoleApp/ConnectionThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package consoleApp;

import java.io.IOException;
import java.net.Socket;
import javaChat.Connection;

/**
*
* @author Christian Janifer
*/
public class ConnectionThread extends Thread {

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 cilent 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");
}
}
}
Loading