summaryrefslogtreecommitdiff
path: root/src/demonstration
diff options
context:
space:
mode:
authorO'Shea <osheas1@wit.edu>2020-12-10 14:03:54 -0500
committerO'Shea <osheas1@wit.edu>2020-12-10 14:03:54 -0500
commitcca61c9f562d2c9e2be13ec16abe134d209b54e3 (patch)
tree3f957b579c45d0536e7e1740acdb0cdbc773f9f4 /src/demonstration
parent690bbba9550e2644e48db44fb94d4df86494a34e (diff)
Final implementation, ready for presentation!
Diffstat (limited to 'src/demonstration')
-rw-r--r--src/demonstration/ChatDEMO$1.classbin0 -> 599 bytes
-rw-r--r--src/demonstration/ChatDEMO$2.classbin0 -> 602 bytes
-rw-r--r--src/demonstration/ChatDEMO$3.classbin0 -> 470 bytes
-rw-r--r--src/demonstration/ChatDEMO.classbin0 -> 6683 bytes
-rw-r--r--src/demonstration/ChatDEMO.java166
-rw-r--r--src/demonstration/ClientDEMO$1.classbin0 -> 1469 bytes
-rw-r--r--src/demonstration/ClientDEMO$2.classbin0 -> 913 bytes
-rw-r--r--src/demonstration/ClientDEMO.classbin0 -> 2208 bytes
-rw-r--r--src/demonstration/ClientDEMO.java110
-rw-r--r--src/demonstration/LoginDEMO$1.classbin0 -> 607 bytes
-rw-r--r--src/demonstration/LoginDEMO$2.classbin0 -> 473 bytes
-rw-r--r--src/demonstration/LoginDEMO.classbin0 -> 6086 bytes
-rw-r--r--src/demonstration/LoginDEMO.java158
13 files changed, 434 insertions, 0 deletions
diff --git a/src/demonstration/ChatDEMO$1.class b/src/demonstration/ChatDEMO$1.class
new file mode 100644
index 0000000..4acd2b3
--- /dev/null
+++ b/src/demonstration/ChatDEMO$1.class
Binary files differ
diff --git a/src/demonstration/ChatDEMO$2.class b/src/demonstration/ChatDEMO$2.class
new file mode 100644
index 0000000..bd4defe
--- /dev/null
+++ b/src/demonstration/ChatDEMO$2.class
Binary files differ
diff --git a/src/demonstration/ChatDEMO$3.class b/src/demonstration/ChatDEMO$3.class
new file mode 100644
index 0000000..68a31bf
--- /dev/null
+++ b/src/demonstration/ChatDEMO$3.class
Binary files differ
diff --git a/src/demonstration/ChatDEMO.class b/src/demonstration/ChatDEMO.class
new file mode 100644
index 0000000..abe7857
--- /dev/null
+++ b/src/demonstration/ChatDEMO.class
Binary files differ
diff --git a/src/demonstration/ChatDEMO.java b/src/demonstration/ChatDEMO.java
new file mode 100644
index 0000000..8156e62
--- /dev/null
+++ b/src/demonstration/ChatDEMO.java
@@ -0,0 +1,166 @@
+package demonstration;
+
+@SuppressWarnings( "javadoc" )
+public class ChatDEMO extends javax.swing.JFrame {
+
+ public boolean messageReady = false ;
+ public String message ;
+ public String username ;
+ /*
+ public void giveTitle(String name)
+ {
+ this.username = name ;
+ setTitle("logged in as:" + name ) ;
+ }
+ */
+ public String getMessageOut()
+ {
+ if( this.message.contentEquals( "" ) || this.message.contentEquals( " " ) )
+ {
+ this.messageReady = false ;
+ return null ;
+ }
+ if( this.messageReady )
+ {
+ this.messageReady = false ;
+ return this.message ;
+ }
+ return null ;
+ }
+
+
+ public void printMessage( String messageOut )
+ {
+ messageOut = String.format( "%s\n%s", this.jTextArea1.getText(), messageOut ) ;
+ this.jTextArea1.setText( null ) ;
+ this.jTextArea1.setText( messageOut ) ;
+ jTextArea1.moveCaretPosition( jTextArea1.getDocument().getLength() );
+ }
+
+
+ public ChatDEMO() {
+ initComponents();
+ }
+
+
+ @SuppressWarnings("unchecked")
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">
+ private void initComponents() {
+
+ jTextField1 = new javax.swing.JTextField();
+ jButton1 = new javax.swing.JButton();
+ jScrollPane2 = new javax.swing.JScrollPane();
+ jTextArea1 = new javax.swing.JTextArea();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
+ setTitle("logged in as: " + this.username );
+
+ jButton1.setText("send");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+
+ jTextField1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jTextField1ActionPerformed(evt);
+ }
+ });
+
+ setResizable(false);
+ jTextArea1.setEditable(false);
+ jTextArea1.setColumns(20);
+ jTextArea1.setRows(5);
+ jTextArea1.setWrapStyleWord(true);
+ jTextArea1.setLineWrap( true );
+ jTextArea1.moveCaretPosition( jTextArea1.getDocument().getLength() );
+ jScrollPane2.setViewportView(jTextArea1);
+
+ 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(50, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
+ .addComponent(jScrollPane2)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 610, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jButton1)))
+ .addGap(50, 50, 50))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap(50, Short.MAX_VALUE)
+ .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 311, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jButton1))
+ .addGap(50, 50, 50))
+ );
+
+ pack();
+ setLocationRelativeTo(null);
+ }// </editor-fold>
+
+ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt)
+ {
+ if( this.jTextField1.getText() != null )
+ {
+ this.message = this.jTextField1.getText() ;
+ this.messageReady = true ;
+ this.jTextField1.setText( null ) ;
+ }
+ }
+
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
+
+ if( this.jTextField1.getText() != null )
+ {
+ this.message = this.jTextField1.getText() ;
+ this.messageReady = true ;
+ this.jTextField1.setText( null ) ;
+ }
+
+ }
+
+
+ public static void main(String args[]) {
+
+ 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(ChatDEMO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(ChatDEMO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(ChatDEMO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(ChatDEMO.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 ChatDEMO().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify
+ private javax.swing.JButton jButton1;
+ private javax.swing.JScrollPane jScrollPane2;
+ private javax.swing.JTextArea jTextArea1;
+ private javax.swing.JTextField jTextField1;
+ // End of variables declaration
+}
diff --git a/src/demonstration/ClientDEMO$1.class b/src/demonstration/ClientDEMO$1.class
new file mode 100644
index 0000000..85074bf
--- /dev/null
+++ b/src/demonstration/ClientDEMO$1.class
Binary files differ
diff --git a/src/demonstration/ClientDEMO$2.class b/src/demonstration/ClientDEMO$2.class
new file mode 100644
index 0000000..8973685
--- /dev/null
+++ b/src/demonstration/ClientDEMO$2.class
Binary files differ
diff --git a/src/demonstration/ClientDEMO.class b/src/demonstration/ClientDEMO.class
new file mode 100644
index 0000000..4b0c46c
--- /dev/null
+++ b/src/demonstration/ClientDEMO.class
Binary files differ
diff --git a/src/demonstration/ClientDEMO.java b/src/demonstration/ClientDEMO.java
new file mode 100644
index 0000000..dbd91b3
--- /dev/null
+++ b/src/demonstration/ClientDEMO.java
@@ -0,0 +1,110 @@
+package demonstration;
+
+import java.net.* ;
+import java.io.* ;
+
+@SuppressWarnings( "javadoc" )
+public class ClientDEMO
+ {
+
+ static LoginDEMO loginDemo = new LoginDEMO() ;
+ static ChatDEMO chatRoom = new ChatDEMO() ;
+
+ @SuppressWarnings( "javadoc" )
+ public static void main( String[] args ) throws IOException
+ {
+
+ loginDemo.setVisible( true );
+
+ boolean done = false ;
+ while( !done )
+ {
+ done = loginDemo.isDone() ;
+ System.out.print("");
+ }
+
+ String ip = loginDemo.getIP() ;
+ String username = loginDemo.getUsername() ;
+
+ // Open your connection to a server, at port 6789
+ Socket socket = new Socket( ip , 6789 ) ;
+
+ // Create communication streams
+ DataInputStream dataStreamIn = new DataInputStream( socket.getInputStream() ) ;
+ DataOutputStream dataStreamOut = new DataOutputStream( socket.getOutputStream() ) ;
+
+ dataStreamOut.writeUTF( username ) ;
+
+ chatRoom.setTitle( "logged in as: " + username ) ;
+ chatRoom.setVisible( true ) ;
+
+ // Thread for sending messages
+ Thread sendMessage = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ while( true )
+ {
+ try
+ {
+ // if-statement is only triggered if client closes window (disconnects)
+ if( !chatRoom.isVisible() )
+ {
+ dataStreamOut.writeUTF( "/quit" ) ;
+ dataStreamIn.close() ;
+ dataStreamOut.close() ;
+ socket.close() ;
+ System.exit( 0 ) ;
+ }
+ // extract message information from GUI text field
+ if( chatRoom.messageReady )
+ {
+ String messageOut = chatRoom.getMessageOut() ;
+ if( messageOut == null )
+ {
+ continue ;
+ }
+ dataStreamOut.writeUTF( messageOut ) ;
+ }
+ System.out.print("") ;
+ }
+ catch( IOException x )
+ {
+ x.printStackTrace() ;
+ System.exit( 0 ) ;
+ }
+ }
+ }
+ }) ;
+
+ // Thread for receiving messages
+ Thread receiveMessage = new Thread( new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ while( true )
+ {
+ try
+ {
+ String messageIn = dataStreamIn.readUTF() ;
+ chatRoom.printMessage( messageIn ) ;
+ }
+ catch( IOException x )
+ {
+ x.printStackTrace() ;
+ System.exit( 0 ) ;
+ }
+ }
+ }
+ });
+
+ // Begin threads
+ sendMessage.start() ;
+ receiveMessage.start() ;
+
+ }
+ }
+ // end class ClientGUI \ No newline at end of file
diff --git a/src/demonstration/LoginDEMO$1.class b/src/demonstration/LoginDEMO$1.class
new file mode 100644
index 0000000..19951a3
--- /dev/null
+++ b/src/demonstration/LoginDEMO$1.class
Binary files differ
diff --git a/src/demonstration/LoginDEMO$2.class b/src/demonstration/LoginDEMO$2.class
new file mode 100644
index 0000000..339afeb
--- /dev/null
+++ b/src/demonstration/LoginDEMO$2.class
Binary files differ
diff --git a/src/demonstration/LoginDEMO.class b/src/demonstration/LoginDEMO.class
new file mode 100644
index 0000000..0acbd60
--- /dev/null
+++ b/src/demonstration/LoginDEMO.class
Binary files differ
diff --git a/src/demonstration/LoginDEMO.java b/src/demonstration/LoginDEMO.java
new file mode 100644
index 0000000..d67f852
--- /dev/null
+++ b/src/demonstration/LoginDEMO.java
@@ -0,0 +1,158 @@
+package demonstration;
+
+@SuppressWarnings( "javadoc" )
+public class LoginDEMO extends javax.swing.JFrame {
+
+ /**
+ * Creates new form loginGUI
+ */
+
+ public String ip ;
+ public String username ;
+ public boolean done ;
+
+ public String getIP()
+ {
+ return this.ip ;
+ }
+
+ public String getUsername()
+ {
+ return this.username ;
+ }
+
+ public boolean isDone()
+ {
+ return this.done ;
+ }
+
+ public LoginDEMO() {
+ initComponents();
+ }
+
+ @SuppressWarnings("unchecked")
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">
+ private void initComponents() {
+
+ jPasswordField1 = new javax.swing.JPasswordField();
+ jLabel1 = new javax.swing.JLabel();
+ jTextField1 = new javax.swing.JTextField();
+ jLabel2 = new javax.swing.JLabel();
+ jLabel3 = new javax.swing.JLabel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("java chat login DEMO");
+ setAlwaysOnTop(true);
+ setResizable(false);
+
+ jPasswordField1.setEditable(false);
+ jPasswordField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
+ jPasswordField1.setText("12.34.56.78");
+
+ jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
+ jLabel1.setText("Enter Server's IP:");
+
+ jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
+ jTextField1.setToolTipText("");
+ jTextField1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jTextField1ActionPerformed(evt);
+ }
+ });
+
+ jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
+ jLabel2.setText("Enter Username:");
+
+ jLabel3.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
+ jLabel3.setText("username must be at least one character");
+ jLabel3.setEnabled(false);
+
+ 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(43, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(jTextField1)
+ .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
+ .addGap(40, 40, 40))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(jLabel3)
+ .addContainerGap())))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(40, 40, 40)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel2))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jLabel3)
+ .addContainerGap(22, Short.MAX_VALUE))
+ );
+
+ pack();
+ setLocationRelativeTo(null);
+ }// </editor-fold>
+
+ private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
+ this.ip = "74.69.251.12" ;
+ if( jTextField1.getText().isBlank() )
+ {
+ jLabel3.setEnabled( true );
+ }
+ else
+ {
+ this.username = jTextField1.getText() ;
+ this.done = true ;
+ dispose();
+ }
+ }
+
+ public static void main(String args[]) {
+ 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(LoginDEMO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(LoginDEMO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(LoginDEMO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(LoginDEMO.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 LoginDEMO().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JPasswordField jPasswordField1;
+ private javax.swing.JTextField jTextField1;
+ // End of variables declaration
+}