Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Needs to be implemented using JAVA , please i need help You need to create the f

ID: 3878655 • Letter: N

Question

Needs to be implemented using JAVA , please i need help

You need to create the following class that extends JFrame:

public class ServerGUI extends JFrame

{

   //Data Fields go here

   //Methods go here

}

Data Fields

You should declare data fields that correspond to the status label, textFields, and the JTextArea as shown below (feel free to implement any other data fields that you like):

private JLabel status; //Initialized to “Not Connected”

private String[] labels = {"Port #", "Timeout"};

private JTextField[] textFields = new JTextField[labels.length];

private JTextArea log;

Methods

You should implement the following methods (feel free to implement any other methods that you like):

public ServerGUI(String title)

Constructor – creates the Server GUI shown above. Input parameter title is used for setting the title bar of the Server GUI.

Getters

public JTextField getTextFieldAt(int index)

Retrieves the corresponding JTextField based in input parameter index. The following valid values for index should be utilized:

0 – Port # JTextField

1 – Timeout JTextField

The purpose of these two JTextFields will become clear in lab2out.

public JLabel getStatus()

Returns the top JLabel of the GUI (initialized to “Not Connected”)

public JTextArea getLog()

Returns the JTextArea pertaining to the Server’s Log. The log area contains all data received from the client as informational messages

Event Handling for JButtons

For now, the following actions should occur when pressing the JButtons

When pressing Listen display “Listen Button Pressed” on the Console

When pressing Close display “Close Button Pressed” on the Console

When pressing Stop display “Stop Button Pressed

When pressing Quit close the GUI (same as pressing the Red X in upper right corner)

Guidelines for Main

ClientGUI and ServerGUI must have their own main methods. The main methods only need to instantiate an object pertaining to each respective class.

The ClientGUI’s main needs at a minimum the following statement:

new ClientGUI(args[0]);

Where args[0] corresponds to the one command line argument pertaining to the desired title of the Client’s GUI

The ServerGUI’s main needs at a minimum the following statement:

new ServerGUI(args[0]);

Where args[0] corresponds to the one command line argument pertaining to the desired title of the Server’s GUI

JLabel JTextField JTextField Server Status: Not Connected Port # Timeout Server Log Below JLabel JTextArea(should be contained within a JSCrollPane so scroll bars can be added as needed) JButtons Listen

Explanation / Answer

here is your ServerGUI class : ------------------->>>>>>>>>>>

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ServerGUI extends JFrame
{
//Data Fields go here
private JLabel status;//
private String[] labels = {"Port #", "Timeout"};
private JTextField[] textFields = new JTextField[labels.length];
private JTextArea log;
private JPanel jpanel1,jpanel2,jpanel3;
private JButton close;
private JButton listen;
private JButton quit;
private JButton stop;
//Methods go here

public ServerGUI(String title){
  super(title);
  setSize(500,500);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setLayout(new BorderLayout());
  prepareGUI();
}

private void prepareGUI(){
  jpanel1 = new JPanel();
  jpanel2 = new JPanel();
  close = new JButton("Close");
  listen = new JButton("Listen");
  for(int i = 0;i<labels.length;i++){
   textFields[i] = new JTextField();
   textFields[i].setColumns(3);
  }
  quit = new JButton("Quit");
  listen.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        // display/center the jdialog when the button is pressed
        System.out.println("Listen Button Pressed");
      }
    });
  close.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        // display/center the jdialog when the button is pressed
        System.out.println("Close Button Pressed");
      }
    });
  quit.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        // display/center the jdialog when the button is pressed
        setVisible(false);
      }
    });
  stop = new JButton("Stop");
  stop.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        // display/center the jdialog when the button is pressed
        System.out.println("Stop Button Pressed");
      }
    });
  status = new JLabel("not connected");
  jpanel3 = new JPanel();
  status.setForeground(Color.RED);
  jpanel1.setLayout(new GridLayout(3,2));
  jpanel1.add(new JLabel("status : ",JLabel.CENTER));
  jpanel1.add(status);
  jpanel1.add(new JLabel(labels[0],JLabel.CENTER));
  jpanel1.add(textFields[0]);
  jpanel1.add(new JLabel(labels[1],JLabel.CENTER));
  jpanel1.add(textFields[1]);
  jpanel3.setLayout(new BoxLayout(jpanel3,BoxLayout.Y_AXIS));
  jpanel3.add(new JLabel("Server Log Below",JLabel.CENTER));
  log = new JTextArea(10,30);
  jpanel3.add(log);

  jpanel2.setLayout(new FlowLayout(FlowLayout.CENTER));
  jpanel2.add(listen);
  jpanel2.add(close);
  jpanel2.add(stop);
  jpanel2.add(quit);
  getContentPane().add(jpanel2,BorderLayout.SOUTH);
  getContentPane().add(jpanel1,BorderLayout.NORTH);
  getContentPane().add(jpanel3,BorderLayout.CENTER);
  setVisible(true);

}

public JTextField getTextFieldAt(int index){
  return textFields[index];
}

public JLabel getStatus(){
  return status;
}

public JTextArea getLog(){
  return log;
}

public static void main(String[] args) {
  ServerGUI s1 = new ServerGUI("server");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote