SlideShare a Scribd company logo
1 of 21
Download to read offline
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package syarifchatting;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.Normalizer.Form;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;
/**
* @author MhdSyarif
* Monday, 13 January 2014, 20 : 52 : 20 WIB
* Tugas III Matakulia Java2SE
* Mhd. Syarif | 49013075
* TKJMD - STEI - ITB
*/
public class Server extends javax.swing.JFrame implements Runnable{
int port= 8080;
Socket client;
ServerSocket server;
BufferedReader Server_Reader, Client_Reader;
BufferedWriter Server_Writer, Client_Writer;
/**
* Creates new form Server
*/
public Server() {
super("www.mhdsyarif.com"); //SetTitle
initComponents();
//Menampilkan hasil ditengah window
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Dimension dialogSize = getSize();
setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
}
//Pilihan ComboBox
private void getComboBox(){
if(ComboBox.getSelectedItem().equals("Server")){
ButtonOn.setText("On");
Username.setText("Server");
}else{
ButtonOn.setText("Connect");
Username.setText("Client");
}
}
//Koneksi client ke server
private void getClientConnec(){
try {
String ip = JOptionPane.showInputDialog(" Input IP Address");
client = new Socket(ip, port);
ComboBox.setEnabled(false);
ButtonOn.setText("Disconnect");
Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
Server_Writer = new BufferedWriter (new OutputStreamWriter(client.getOutputStream()));
} catch (UnknownHostException ex) {
System.out.println("Accept Failed");
System.exit(-1);
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void getReadConnec(){
// try {
// try {
// try {
// server = new ServerSocket(port);
// this.setTitle("Please Wait");
// } catch (IOException ex) {
// System.out.println("Could not listen");
// System.exit(-1);
// }
// client = server.accept();
// this.setTitle("Connected" + client.getInetAddress());
// } catch (IOException ex) {
// System.out.println("Accept Failed");
// System.exit(-1);
// }
// Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
// Server_Writer = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
// } catch (IOException ex) {
// System.out.println("Read Failed");
// System.exit(-1);
// }
final int PORT = 8080;
try {
server = new ServerSocket(PORT);
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Server started...");
System.out.println("Wating for clients...");
while (true) {
try {
client = server.accept();
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
Thread t = new Thread() {
public void run() {
try {
Server_Reader = new BufferedReader(new
InputStreamReader(client.getInputStream()));
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Server_Writer = new BufferedWriter (new
OutputStreamWriter(client.getOutputStream()));
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
try (
PrintWriter out = new PrintWriter(client.getOutputStream(), true);
Scanner in = new Scanner(client.getInputStream());
) {
while (in.hasNextLine()) {
String input = in.nextLine();
if (input.equalsIgnoreCase("exit")) {
break;
}
System.out.println("Received radius from client: " + input);
// double radius = Double.valueOf(input);
// double area = Math.PI* radius *radius ;
// out.println(area);
}
} catch (IOException e) { }
}
};
t.start();
}
}
private void getDisconnectedClient(){
try {
client.close();
Server_Reader.close();
Server_Writer.close();
ComboBox.setEnabled(true);
ButtonOn.setText("Connect");
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void getDisconnectedServer(){
try {
Server_Reader.close();
Server_Writer.close();
ButtonOn.setText("On");
this.setTitle("Disconected");
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void getButtonOn(){
if(ButtonOn.getText().equals("Connect"))
{
ButtonOn.setText("DIsconnect");
getClientConnec();
Thread thread1= new Thread(this);
Thread thread2= new Thread(this);
Thread thread3= new Thread(this);
Thread thread4= new Thread(this);
Thread thread5= new Thread(this);
Thread thread6= new Thread(this);
Thread thread7= new Thread(this);
Thread thread8= new Thread(this);
Thread thread9= new Thread(this);
Thread thread10= new Thread(this);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();
thread6.start();
thread7.start();
thread8.start();
thread9.start();
thread10.start();
} else if(ComboBox.getSelectedItem().equals("Server")){
ButtonOn.setText("Off");
getReadConnec();
Thread thread1= new Thread(this);
Thread thread2= new Thread(this);
Thread thread3= new Thread(this);
Thread thread4= new Thread(this);
Thread thread5= new Thread(this);
Thread thread6= new Thread(this);
Thread thread7= new Thread(this);
Thread thread8= new Thread(this);
Thread thread9= new Thread(this);
Thread thread10= new Thread(this);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();
thread6.start();
thread7.start();
thread8.start();
thread9.start();
thread10.start();
}else if(ButtonOn.getText().equals("Disconnect")){
getDisconnectedClient();
}else if(ButtonOn.getText().equals("Off")){
getDisconnectedServer();
}
}
private void getSend(){
try {
Server_Writer.write(Username.getText()+ ": " +TextChat.getText());
Server_Writer.newLine();
Server_Writer.flush();
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
ListChat.add(Username.getText()+ ": " +TextChat.getText());
//jClient.setText(Username.getText());
TextChat.setText("");
}
//Background color
public void getBackgroundColor(){
Color c = JColorChooser.showDialog(null,"Background Color",jPanel.getBackground());
jPanel.setBackground(c);
}
//Konfirmasi keluar
public void getExit(){
int confirm =JOptionPane.showConfirmDialog(this,"Are you sure will exit this application ?","Exit
Application",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if (confirm == JOptionPane.YES_OPTION){
System.exit(0);
}
}
/**
* 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">
private void initComponents() {
Dialog = new javax.swing.JDialog();
ColorChooser = new javax.swing.JColorChooser();
jPanel = new javax.swing.JPanel();
ComboBox = new javax.swing.JComboBox();
ButtonOn = new javax.swing.JButton();
Send = new javax.swing.JToggleButton();
JUsername = new javax.swing.JLabel();
Username = new javax.swing.JTextField();
TextChat = new java.awt.TextArea();
ListChat = new java.awt.List();
jMenuBar1 = new javax.swing.JMenuBar();
File = new javax.swing.JMenu();
BackgroundColor = new javax.swing.JMenuItem();
Exit = new javax.swing.JMenuItem();
Help = new javax.swing.JMenu();
About = new javax.swing.JMenuItem();
javax.swing.GroupLayout DialogLayout = new
javax.swing.GroupLayout(Dialog.getContentPane());
Dialog.getContentPane().setLayout(DialogLayout);
DialogLayout.setHorizontalGroup(
DialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DialogLayout.createSequentialGroup()
.addContainerGap()
.addComponent(ColorChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 601,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
DialogLayout.setVerticalGroup(
DialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(DialogLayout.createSequentialGroup()
.addContainerGap()
.addComponent(ColorChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 316,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setBackground(new java.awt.Color(204, 204, 204));
setResizable(false);
jPanel.setBackground(new java.awt.Color(204, 204, 204));
ComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Server", "Client"
}));
ComboBox.setToolTipText("");
ComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ComboBoxActionPerformed(evt);
}
});
ButtonOn.setText("On");
ButtonOn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonOnActionPerformed(evt);
}
});
Send.setText("SEND");
Send.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SendActionPerformed(evt);
}
});
JUsername.setText("Username");
Username.setText("Server");
javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(jPanel);
jPanel.setLayout(jPanelLayout);
jPanelLayout.setHorizontalGroup(
jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelLayout.createSequentialGroup()
.addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanelLayout.createSequentialGroup()
.addComponent(JUsername)
.addGap(18, 18, 18)
.addComponent(Username, javax.swing.GroupLayout.PREFERRED_SIZE, 237,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(ComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(ButtonOn, javax.swing.GroupLayout.DEFAULT_SIZE, 99,
Short.MAX_VALUE))
.addComponent(ListChat, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanelLayout.createSequentialGroup()
.addComponent(TextChat, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Send, javax.swing.GroupLayout.PREFERRED_SIZE, 74,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanelLayout.setVerticalGroup(
jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelLayout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ButtonOn))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(JUsername)
.addComponent(Username, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ListChat, javax.swing.GroupLayout.PREFERRED_SIZE, 179,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(TextChat, javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Send, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
File.setText("File");
BackgroundColor.setText("Background Color");
BackgroundColor.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BackgroundColorActionPerformed(evt);
}
});
File.add(BackgroundColor);
Exit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W,
java.awt.event.InputEvent.CTRL_MASK));
Exit.setText("Exit");
Exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ExitActionPerformed(evt);
}
});
File.add(Exit);
jMenuBar1.add(File);
Help.setText("Help");
About.setText("About");
About.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AboutActionPerformed(evt);
}
});
Help.add(About);
jMenuBar1.add(Help);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void AboutActionPerformed(java.awt.event.ActionEvent evt) {
About a = new About();
a.setVisible(true);// TODO add your handling code here:
}
private void SendActionPerformed(java.awt.event.ActionEvent evt) {
getSend();// TODO add your handling code here:
}
private void ButtonOnActionPerformed(java.awt.event.ActionEvent evt) {
getButtonOn();
// TODO add your handling code here:
}
private void ComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
getComboBox();
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
getExit();// TODO add your handling code here:
}
private void BackgroundColorActionPerformed(java.awt.event.ActionEvent evt) {
getBackgroundColor();// TODO add your handling code here:
}
/**
* @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(Server.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Server().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenuItem About;
private javax.swing.JMenuItem BackgroundColor;
private javax.swing.JButton ButtonOn;
private javax.swing.JColorChooser ColorChooser;
private javax.swing.JComboBox ComboBox;
private javax.swing.JDialog Dialog;
private javax.swing.JMenuItem Exit;
private javax.swing.JMenu File;
private javax.swing.JMenu Help;
private javax.swing.JLabel JUsername;
private java.awt.List ListChat;
private javax.swing.JToggleButton Send;
private java.awt.TextArea TextChat;
private javax.swing.JTextField Username;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel;
// End of variables declaration
@Override
public void run()
{
try {
ListChat.add(Server_Reader.readLine());
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Keterangan : permasalahan saat di RUN aplikasi sudah berhasil dijalankan,akan tetapi hanya bisa
1 server dan 1 client saja akan tetapi tidak bisa lebih. Dan telah muncul dilast text saat mengirim
cahttingan
Server hanya bisa menerima 1 client saja, jika lebih tidak muncur di list text

More Related Content

What's hot

2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistAnton Arhipov
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coinsoft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coinsoft-shake.ch
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client servertrilestari08
 
What’s new in C# 6
What’s new in C# 6What’s new in C# 6
What’s new in C# 6Fiyaz Hasan
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsAnton Arhipov
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsAndrei Pangin
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestHoward Lewis Ship
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authenticationWindowsPhoneRocks
 

What's hot (20)

Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with Javassist
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coinsoft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
 
Code red SUM
Code red SUMCode red SUM
Code red SUM
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
Live Updating Swift Code
Live Updating Swift CodeLive Updating Swift Code
Live Updating Swift Code
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client server
 
What’s new in C# 6
What’s new in C# 6What’s new in C# 6
What’s new in C# 6
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
Spock framework
Spock frameworkSpock framework
Spock framework
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap Dumps
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
JavaExamples
JavaExamplesJavaExamples
JavaExamples
 
JDK Power Tools
JDK Power ToolsJDK Power Tools
JDK Power Tools
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authentication
 

Similar to Server1

Laporan tugas network programming
Laporan tugas network programmingLaporan tugas network programming
Laporan tugas network programmingRahmatHamdani2
 
Hi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdfHi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdffashiongallery1
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습DoHyun Jung
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harianKhairunnisaPekanbaru
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdffatoryoutlets
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
Testing in android
Testing in androidTesting in android
Testing in androidjtrindade
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agentsRafael Winterhalter
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 SpringKiyotaka Oku
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxhendriciraida
 
forwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docxforwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docxbudbarber38650
 

Similar to Server1 (20)

Laporan tugas network programming
Laporan tugas network programmingLaporan tugas network programming
Laporan tugas network programming
 
Hi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdfHi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdf
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian
 
Fia fabila
Fia fabilaFia fabila
Fia fabila
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
My java file
My java fileMy java file
My java file
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
 
DCN Practical
DCN PracticalDCN Practical
DCN Practical
 
Testing in android
Testing in androidTesting in android
Testing in android
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docx
 
forwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docxforwarder.java.txt java forwarder class waits for an in.docx
forwarder.java.txt java forwarder class waits for an in.docx
 

Recently uploaded

哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...wyqazy
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Niamh verma
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝soniya singh
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 

Recently uploaded (7)

哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 

Server1

  • 1. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package syarifchatting; import java.awt.Color; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.net.UnknownHostException; import java.text.Normalizer.Form; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JColorChooser; import javax.swing.JOptionPane; /** * @author MhdSyarif * Monday, 13 January 2014, 20 : 52 : 20 WIB * Tugas III Matakulia Java2SE
  • 2. * Mhd. Syarif | 49013075 * TKJMD - STEI - ITB */ public class Server extends javax.swing.JFrame implements Runnable{ int port= 8080; Socket client; ServerSocket server; BufferedReader Server_Reader, Client_Reader; BufferedWriter Server_Writer, Client_Writer; /** * Creates new form Server */ public Server() { super("www.mhdsyarif.com"); //SetTitle initComponents(); //Menampilkan hasil ditengah window java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); java.awt.Dimension dialogSize = getSize(); setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); } //Pilihan ComboBox private void getComboBox(){ if(ComboBox.getSelectedItem().equals("Server")){ ButtonOn.setText("On");
  • 3. Username.setText("Server"); }else{ ButtonOn.setText("Connect"); Username.setText("Client"); } } //Koneksi client ke server private void getClientConnec(){ try { String ip = JOptionPane.showInputDialog(" Input IP Address"); client = new Socket(ip, port); ComboBox.setEnabled(false); ButtonOn.setText("Disconnect"); Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream())); Server_Writer = new BufferedWriter (new OutputStreamWriter(client.getOutputStream())); } catch (UnknownHostException ex) { System.out.println("Accept Failed"); System.exit(-1); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } } private void getReadConnec(){ // try { // try {
  • 4. // try { // server = new ServerSocket(port); // this.setTitle("Please Wait"); // } catch (IOException ex) { // System.out.println("Could not listen"); // System.exit(-1); // } // client = server.accept(); // this.setTitle("Connected" + client.getInetAddress()); // } catch (IOException ex) { // System.out.println("Accept Failed"); // System.exit(-1); // } // Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream())); // Server_Writer = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); // } catch (IOException ex) { // System.out.println("Read Failed"); // System.exit(-1); // } final int PORT = 8080; try { server = new ServerSocket(PORT); } catch (IOException ex) {
  • 5. Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Server started..."); System.out.println("Wating for clients..."); while (true) { try { client = server.accept(); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } Thread t = new Thread() { public void run() { try { Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream())); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } try { Server_Writer = new BufferedWriter (new OutputStreamWriter(client.getOutputStream())); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } try ( PrintWriter out = new PrintWriter(client.getOutputStream(), true);
  • 6. Scanner in = new Scanner(client.getInputStream()); ) { while (in.hasNextLine()) { String input = in.nextLine(); if (input.equalsIgnoreCase("exit")) { break; } System.out.println("Received radius from client: " + input); // double radius = Double.valueOf(input); // double area = Math.PI* radius *radius ; // out.println(area); } } catch (IOException e) { } } }; t.start(); } } private void getDisconnectedClient(){ try { client.close(); Server_Reader.close(); Server_Writer.close(); ComboBox.setEnabled(true);
  • 7. ButtonOn.setText("Connect"); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } } private void getDisconnectedServer(){ try { Server_Reader.close(); Server_Writer.close(); ButtonOn.setText("On"); this.setTitle("Disconected"); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } } private void getButtonOn(){ if(ButtonOn.getText().equals("Connect")) { ButtonOn.setText("DIsconnect"); getClientConnec(); Thread thread1= new Thread(this); Thread thread2= new Thread(this); Thread thread3= new Thread(this); Thread thread4= new Thread(this); Thread thread5= new Thread(this);
  • 8. Thread thread6= new Thread(this); Thread thread7= new Thread(this); Thread thread8= new Thread(this); Thread thread9= new Thread(this); Thread thread10= new Thread(this); thread1.start(); thread2.start(); thread3.start(); thread4.start(); thread5.start(); thread6.start(); thread7.start(); thread8.start(); thread9.start(); thread10.start(); } else if(ComboBox.getSelectedItem().equals("Server")){ ButtonOn.setText("Off"); getReadConnec(); Thread thread1= new Thread(this); Thread thread2= new Thread(this); Thread thread3= new Thread(this); Thread thread4= new Thread(this); Thread thread5= new Thread(this); Thread thread6= new Thread(this); Thread thread7= new Thread(this); Thread thread8= new Thread(this); Thread thread9= new Thread(this);
  • 9. Thread thread10= new Thread(this); thread1.start(); thread2.start(); thread3.start(); thread4.start(); thread5.start(); thread6.start(); thread7.start(); thread8.start(); thread9.start(); thread10.start(); }else if(ButtonOn.getText().equals("Disconnect")){ getDisconnectedClient(); }else if(ButtonOn.getText().equals("Off")){ getDisconnectedServer(); } } private void getSend(){ try { Server_Writer.write(Username.getText()+ ": " +TextChat.getText()); Server_Writer.newLine(); Server_Writer.flush(); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } ListChat.add(Username.getText()+ ": " +TextChat.getText());
  • 10. //jClient.setText(Username.getText()); TextChat.setText(""); } //Background color public void getBackgroundColor(){ Color c = JColorChooser.showDialog(null,"Background Color",jPanel.getBackground()); jPanel.setBackground(c); } //Konfirmasi keluar public void getExit(){ int confirm =JOptionPane.showConfirmDialog(this,"Are you sure will exit this application ?","Exit Application",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if (confirm == JOptionPane.YES_OPTION){ System.exit(0); } } /** * 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"> private void initComponents() {
  • 11. Dialog = new javax.swing.JDialog(); ColorChooser = new javax.swing.JColorChooser(); jPanel = new javax.swing.JPanel(); ComboBox = new javax.swing.JComboBox(); ButtonOn = new javax.swing.JButton(); Send = new javax.swing.JToggleButton(); JUsername = new javax.swing.JLabel(); Username = new javax.swing.JTextField(); TextChat = new java.awt.TextArea(); ListChat = new java.awt.List(); jMenuBar1 = new javax.swing.JMenuBar(); File = new javax.swing.JMenu(); BackgroundColor = new javax.swing.JMenuItem(); Exit = new javax.swing.JMenuItem(); Help = new javax.swing.JMenu(); About = new javax.swing.JMenuItem(); javax.swing.GroupLayout DialogLayout = new javax.swing.GroupLayout(Dialog.getContentPane()); Dialog.getContentPane().setLayout(DialogLayout); DialogLayout.setHorizontalGroup( DialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(DialogLayout.createSequentialGroup() .addContainerGap() .addComponent(ColorChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 601, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) );
  • 12. DialogLayout.setVerticalGroup( DialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(DialogLayout.createSequentialGroup() .addContainerGap() .addComponent(ColorChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setBackground(new java.awt.Color(204, 204, 204)); setResizable(false); jPanel.setBackground(new java.awt.Color(204, 204, 204)); ComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Server", "Client" })); ComboBox.setToolTipText(""); ComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ComboBoxActionPerformed(evt); } }); ButtonOn.setText("On"); ButtonOn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ButtonOnActionPerformed(evt);
  • 13. } }); Send.setText("SEND"); Send.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SendActionPerformed(evt); } }); JUsername.setText("Username"); Username.setText("Server"); javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(jPanel); jPanel.setLayout(jPanelLayout); jPanelLayout.setHorizontalGroup( jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelLayout.createSequentialGroup() .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanelLayout.createSequentialGroup() .addComponent(JUsername) .addGap(18, 18, 18)
  • 14. .addComponent(Username, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(ComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(18, 18, 18) .addComponent(ButtonOn, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)) .addComponent(ListChat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanelLayout.createSequentialGroup() .addComponent(TextChat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Send, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); jPanelLayout.setVerticalGroup( jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelLayout.createSequentialGroup() .addGap(18, 18, 18) .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ButtonOn)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(JUsername)
  • 15. .addComponent(Username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ListChat, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(TextChat, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Send, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); File.setText("File"); BackgroundColor.setText("Background Color"); BackgroundColor.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { BackgroundColorActionPerformed(evt); } }); File.add(BackgroundColor); Exit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK)); Exit.setText("Exit"); Exit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {
  • 16. ExitActionPerformed(evt); } }); File.add(Exit); jMenuBar1.add(File); Help.setText("Help"); About.setText("About"); About.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AboutActionPerformed(evt); } }); Help.add(About); jMenuBar1.add(Help); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) );
  • 17. layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold> private void AboutActionPerformed(java.awt.event.ActionEvent evt) { About a = new About(); a.setVisible(true);// TODO add your handling code here: } private void SendActionPerformed(java.awt.event.ActionEvent evt) { getSend();// TODO add your handling code here: } private void ButtonOnActionPerformed(java.awt.event.ActionEvent evt) { getButtonOn(); // TODO add your handling code here: } private void ComboBoxActionPerformed(java.awt.event.ActionEvent evt) { getComboBox(); }
  • 18. private void ExitActionPerformed(java.awt.event.ActionEvent evt) { getExit();// TODO add your handling code here: } private void BackgroundColorActionPerformed(java.awt.event.ActionEvent evt) { getBackgroundColor();// TODO add your handling code here: } /** * @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(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  • 19. } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Server().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JMenuItem About; private javax.swing.JMenuItem BackgroundColor; private javax.swing.JButton ButtonOn; private javax.swing.JColorChooser ColorChooser; private javax.swing.JComboBox ComboBox; private javax.swing.JDialog Dialog; private javax.swing.JMenuItem Exit; private javax.swing.JMenu File; private javax.swing.JMenu Help;
  • 20. private javax.swing.JLabel JUsername; private java.awt.List ListChat; private javax.swing.JToggleButton Send; private java.awt.TextArea TextChat; private javax.swing.JTextField Username; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JPanel jPanel; // End of variables declaration @Override public void run() { try { ListChat.add(Server_Reader.readLine()); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } } }
  • 21. Keterangan : permasalahan saat di RUN aplikasi sudah berhasil dijalankan,akan tetapi hanya bisa 1 server dan 1 client saja akan tetapi tidak bisa lebih. Dan telah muncul dilast text saat mengirim cahttingan Server hanya bisa menerima 1 client saja, jika lebih tidak muncur di list text