Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Using Netbeans IDE I need help getting started with the parts of the code below that are in bold. Declare 3 objects with Socket,

Java

Using Netbeans IDE

I need help getting started with the parts of the code below that are in bold.

Declare 3 objects with Socket, PrintWriter and BufferedReader, so they are visible throughout the program.

import java.io.*;

import java.net.*;

public class kkClient extends javax.swing.JFrame {

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

private void connectActionPerformed(java.awt.event.ActionEvent evt) { /* If client is disconnected button should say "connect" (which it does now) if client is connected the button should say "disconnect"(Having trouble with this part). getText() method is used to get host IP and port number. When discconect is clicked the socket and I/O objects should be closed and the button should revert back to "Connect."

try { Socket mySocket = new Socket(serverName.getText(), Integer.parseInt(port.getText())); //System.out.println(mySocket.getPort()); output.append("Connected to Server "); }

private void sendActionPerformed(java.awt.event.ActionEvent evt) { /* If for some reason you got disconnected, you won't be able to send messages to the server. This exception must be dealt with. Display messages you sent in the text area the follwoing format: "Client ........", write the message to the socket (printwriterObj.println() method), and wait for the server's response (bufferedreaderObj.readLine() method.) */

} }

private void messageActionPerformed(java.awt.event.ActionEvent evt) { // This is the user input message to be sent to the server from client. } catch (IOException e) { output.append("Connection error!! "); } } 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(kkClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(kkClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(kkClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(kkClient.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 kkClient().setVisible(true); } }); }

// Variables declaration - do not modify private javax.swing.JButton connect; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField message; private javax.swing.JTextArea output; private javax.swing.JTextField port; private javax.swing.JButton send; private javax.swing.JTextField serverName; // End of variables declaration }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write the difference between sexual and asexual reproduction.

Answered: 1 week ago

Question

What your favourite topic in mathematics?

Answered: 1 week ago