diff --git a/bin/javaChat/ChatClient$1.class b/bin/javaChat/ChatClient$1.class index 48518d4..63f587a 100644 Binary files a/bin/javaChat/ChatClient$1.class and b/bin/javaChat/ChatClient$1.class differ diff --git a/bin/javaChat/ChatClient$2.class b/bin/javaChat/ChatClient$2.class index b29261b..03c4556 100644 Binary files a/bin/javaChat/ChatClient$2.class and b/bin/javaChat/ChatClient$2.class differ diff --git a/bin/javaChat/ChatClient.class b/bin/javaChat/ChatClient.class index 67ca78e..54450fb 100644 Binary files a/bin/javaChat/ChatClient.class and b/bin/javaChat/ChatClient.class differ diff --git a/bin/javaChat/ClientGUI$1.class b/bin/javaChat/ClientGUI$1.class new file mode 100644 index 0000000..9c0d6d3 Binary files /dev/null and b/bin/javaChat/ClientGUI$1.class differ diff --git a/bin/javaChat/ClientGUI$2.class b/bin/javaChat/ClientGUI$2.class new file mode 100644 index 0000000..d3440f6 Binary files /dev/null and b/bin/javaChat/ClientGUI$2.class differ diff --git a/bin/javaChat/ClientGUI.class b/bin/javaChat/ClientGUI.class new file mode 100644 index 0000000..adaa1d5 Binary files /dev/null and b/bin/javaChat/ClientGUI.class differ diff --git a/bin/javaChat/UserInterface$1.class b/bin/javaChat/UserInterface$1.class new file mode 100644 index 0000000..1eb0b93 Binary files /dev/null and b/bin/javaChat/UserInterface$1.class differ diff --git a/bin/javaChat/UserInterface$2.class b/bin/javaChat/UserInterface$2.class new file mode 100644 index 0000000..e082f5f Binary files /dev/null and b/bin/javaChat/UserInterface$2.class differ diff --git a/bin/javaChat/UserInterface$3.class b/bin/javaChat/UserInterface$3.class new file mode 100644 index 0000000..9347be1 Binary files /dev/null and b/bin/javaChat/UserInterface$3.class differ diff --git a/bin/javaChat/UserInterface$4.class b/bin/javaChat/UserInterface$4.class new file mode 100644 index 0000000..af911d4 Binary files /dev/null and b/bin/javaChat/UserInterface$4.class differ diff --git a/bin/javaChat/UserInterface$5.class b/bin/javaChat/UserInterface$5.class new file mode 100644 index 0000000..bfcb669 Binary files /dev/null and b/bin/javaChat/UserInterface$5.class differ diff --git a/bin/javaChat/UserInterface$6.class b/bin/javaChat/UserInterface$6.class new file mode 100644 index 0000000..87e9a3f Binary files /dev/null and b/bin/javaChat/UserInterface$6.class differ diff --git a/bin/javaChat/UserInterface.class b/bin/javaChat/UserInterface.class new file mode 100644 index 0000000..3487c2f Binary files /dev/null and b/bin/javaChat/UserInterface.class differ diff --git a/bin/module-info.class b/bin/module-info.class index 5ca383f..afd089f 100644 Binary files a/bin/module-info.class and b/bin/module-info.class differ diff --git a/src/javaChat/ChatClient.java b/src/javaChat/ChatClient.java index a342832..9560b49 100644 --- a/src/javaChat/ChatClient.java +++ b/src/javaChat/ChatClient.java @@ -1,6 +1,9 @@ package javaChat; import java.net.* ; + +import javax.swing.JFrame ; + import java.io.* ; public class ChatClient @@ -14,6 +17,7 @@ public class ChatClient */ public static void main( String[] args ) throws IOException { + // Get server IP BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) ) ; System.out.print( "\nPlease enter the IP of the desired server: " ); // GUI: IP BOX diff --git a/src/javaChat/ClientGUI.java b/src/javaChat/ClientGUI.java new file mode 100644 index 0000000..3b98486 --- /dev/null +++ b/src/javaChat/ClientGUI.java @@ -0,0 +1,97 @@ +package javaChat; + +import java.net.* ; +import java.io.* ; + +/** + * + * + * @author osheas1 + * @version 1.0.0 2020-12-07 Initial implementation + * + */ +public class ClientGUI + { + + public static void main( String[] args ) throws IOException + { + + UserInterface login = new UserInterface() ; + login.setVisible( true ); + + boolean done = false ; + while( !done ) + { + done = login.isDone() ; + System.out.print(""); + } + + String ip = login.getIP() ; + String username = login.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() ) ; + + BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) ) ; + + dataStreamOut.writeUTF( username ) ; + + // Thread for sending messages + Thread sendMessage = new Thread(new Runnable() + { + @Override + public void run() + { + System.out.print( "\n-= Type /help for a list of commands =-" ) ; + while( true ) + { + try + { + String messageOut = keyboard.readLine() ; + dataStreamOut.writeUTF( messageOut ) ; + } + 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() ; + System.out.printf( "%n%s\n", 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/javaChat/UserInterface.java b/src/javaChat/UserInterface.java new file mode 100644 index 0000000..1d8f906 --- /dev/null +++ b/src/javaChat/UserInterface.java @@ -0,0 +1,288 @@ +package javaChat; + +import java.awt.* ; +import java.util.* ; +import javax.swing.* ; + +public class UserInterface extends javax.swing.JFrame { + + + String ip ; + String username ; + boolean done ; + +/** + * Creates new form loginFrame + */ +public UserInterface() { + 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") +// +private void initComponents() + { + + jTextField1 = new javax.swing.JTextField(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jTextField2 = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + jSlider1 = new javax.swing.JSlider(); + jSlider2 = new javax.swing.JSlider(); + jSlider3 = new javax.swing.JSlider(); + jSlider4 = new javax.swing.JSlider(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Java Chat"); + setAlwaysOnTop(true); + setBackground(new java.awt.Color(255, 255, 255)); + setForeground(java.awt.Color.white); + setResizable(false); + + jTextField1.setEditable(false); + jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER); + jTextField1.setText("0.0.0.0"); + + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel1.setText("Enter Server's I.P. Address:"); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel2.setText("Enter your desired username:"); + + jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER); + jTextField2.setActionCommand(""); + + jButton1.setText("Connect"); + jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + jButton1.setOpaque(false); + jButton1.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jButton1MouseClicked(evt); + } + }); + + jSlider1.setMaximum(999); + jSlider1.setOrientation(javax.swing.JSlider.VERTICAL); + jSlider1.setValue(0); + jSlider1.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + jSlider1StateChanged(evt); + } + }); + + jSlider2.setMaximum(999); + jSlider2.setOrientation(javax.swing.JSlider.VERTICAL); + jSlider2.setValue(0); + jSlider2.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + jSlider2StateChanged(evt); + } + }); + + jSlider3.setMaximum(999); + jSlider3.setOrientation(javax.swing.JSlider.VERTICAL); + jSlider3.setValue(0); + jSlider3.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + jSlider3StateChanged(evt); + } + }); + + jSlider4.setMaximum(999); + jSlider4.setOrientation(javax.swing.JSlider.VERTICAL); + jSlider4.setValue(0); + jSlider4.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + jSlider4StateChanged(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() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(60, 60, 60) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(18, 18, 18) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addGroup(layout.createSequentialGroup() + .addGap(162, 162, 162) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE) + .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jSlider3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jSlider4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(56, 56, 56)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(24, 24, 24) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jSlider3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jSlider4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(40, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .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(jLabel1)) + .addGap(36, 36, 36) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2)) + .addGap(28, 28, 28) + .addComponent(jButton1) + .addGap(30, 30, 30)))) + ); + + pack(); + }// + +private void jButton1MouseClicked(java.awt.event.MouseEvent evt) + { + ip = jTextField1.getText() ; + username = jTextField2.getText() ; + //System.out.printf( "IP: %s \nUsername: %s\n", ip, username ) ; + + + done = true ; + setVisible( false ) ; + dispose() ; + + } + +private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) + { + Integer a = jSlider1.getValue() ; + Integer b = jSlider2.getValue() ; + Integer c = jSlider3.getValue() ; + Integer d = jSlider4.getValue() ; + + String ip = String.format("%s.%s.%s.%s", a, b, c, d) ; + + jTextField1.setText( ip.toString() ) ; + } + +private void jSlider2StateChanged(javax.swing.event.ChangeEvent evt) + { + Integer a = jSlider1.getValue() ; + Integer b = jSlider2.getValue() ; + Integer c = jSlider3.getValue() ; + Integer d = jSlider4.getValue() ; + + String ip = String.format("%s.%s.%s.%s", a, b, c, d) ; + + jTextField1.setText( ip.toString() ) ; + } + +private void jSlider3StateChanged(javax.swing.event.ChangeEvent evt) + { + Integer a = jSlider1.getValue() ; + Integer b = jSlider2.getValue() ; + Integer c = jSlider3.getValue() ; + Integer d = jSlider4.getValue() ; + + String ip = String.format("%s.%s.%s.%s", a, b, c, d) ; + + jTextField1.setText( ip.toString() ) ; + } + +private void jSlider4StateChanged(javax.swing.event.ChangeEvent evt) + { + Integer a = jSlider1.getValue() ; + Integer b = jSlider2.getValue() ; + Integer c = jSlider3.getValue() ; + Integer d = jSlider4.getValue() ; + + String ip = String.format("%s.%s.%s.%s", a, b, c, d) ; + + jTextField1.setText( ip.toString() ) ; + } + +/** + * @param args the command line arguments + */ +public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* 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(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new UserInterface().setVisible(true); + } + }); +} + + +public String getIP() + { + return ip ; + } + +public String getUsername() + { + return username ; + } + +public boolean isDone() + { + return done ; + } + +// Variables declaration - do not modify +private javax.swing.JButton jButton1; +private javax.swing.JLabel jLabel1; +private javax.swing.JLabel jLabel2; +private javax.swing.JSlider jSlider1; +private javax.swing.JSlider jSlider2; +private javax.swing.JSlider jSlider3; +private javax.swing.JSlider jSlider4; +private javax.swing.JTextField jTextField1; +private javax.swing.JTextField jTextField2; +// End of variables declaration +} diff --git a/src/module-info.java b/src/module-info.java index 2d8c047..8a62a02 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -7,4 +7,5 @@ */ module javaChat { - requires java.desktop;} \ No newline at end of file + requires java.desktop; + requires java.logging;} \ No newline at end of file