Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with this java GUI, I provided my code to help. Might have to space it out, it was too long to

Can someone help me with this java GUI, I provided my code to help. Might have to space it out, it was too long to put in line by lineimage text in transcribedimage text in transcribedimage text in transcribed

import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.GroupLayout;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.LayoutStyle;import javax.swing.WindowConstants;public class ServerGUI extends javax.swing.JFrame { private JButton btnClose; private JButton btnListen; private JButton btnQuit; private JButton btnStop;private JScrollPane jScrollPane1;private JLabel lblCliendID;private JLabel lblServerData; private JLabel lblServerURL; private JLabel lblStatus; private JLabel lblStatusConnectDisconnect; private JTextArea txtAreaClientData1; private JTextField txtClientID; private JTextField txtClientID1; public ServerGUI(String title) { this.setTitle("Server"); //set the title lblStatusConnectDisconnect = new JLabel(); lblCliendID = new JLabel(); btnQuit = new JButton();btnClose = new JButton(); btnStop = new JButton();lblStatus = new JLabel(); lblServerURL = new JLabel(); lblServerData = new JLabel(); txtClientID = new JTextField();txtClientID1 = new JTextField(); jScrollPane1 = new JScrollPane(); txtAreaClientData1 = new JTextArea();btnListen = new JButton(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); lblStatusConnectDisconnect.setBackground(Color.RED); lblStatusConnectDisconnect.setText("Not Connected"); lblCliendID.setText("Port #"); btnQuit.setText("Quit"); btnQuit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnQuitActionPerformed(evt);}}); btnClose.setText("Close"); btnClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnCloseActionPerformed(evt);}}); btnStop.setText("Stop"); btnStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnStopActionPerformed(evt);}});btnListen.setText("Listen"); btnListen.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnListenActionPerformed(evt);}}); lblStatus.setText("Status"); lblServerURL.setText("Time Out"); lblServerData.setText("Server Log Below"); txtAreaClientData1.setColumns(20); txtAreaClientData1.setRows(5); jScrollPane1.setViewportView(txtAreaClientData1); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(188, 188, 188) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout .createParallelGroup(GroupLayout.Alignment.TRAILING, false) .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(lblServerURL, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(txtClientID1, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE) .addGap(0, 90, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(lblCliendID, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE) .addGap(10, 10, 10).addComponent(txtClientID, GroupLayout.PREFERRED_SIZE, 162, GroupLayout.PREFERRED_SIZE))) .addComponent(lblServerData, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup().addGap(169, 169, 169).addComponent(lblStatus) .addGap(11, 11, 11) .addComponent(lblStatusConnectDisconnect, GroupLayout.PREFERRED_SIZE, 185, GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(17, 17, 17).addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 459, GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(45, 45, 45).addComponent(btnListen) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnClose) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnStop, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnQuit, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE))) .addContainerGap(24, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(lblStatus).addComponent(lblStatusConnectDisconnect)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10).addComponent(lblCliendID)) .addComponent(txtClientID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(lblServerURL) .addComponent(txtClientID1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(66, 66, 66).addComponent(lblServerData) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE) .addGap(2, 2, 2) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(btnStop).addComponent(btnClose).addComponent(btnQuit) .addComponent(btnListen)) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));pack(); setLocationRelativeTo(null);} private void btnQuitActionPerformed(ActionEvent evt) { lblStatusConnectDisconnect.setText("Quit Button pressed"); //System.exit(0); //exit application } private void btnCloseActionPerformed(ActionEvent evt) { lblStatusConnectDisconnect.setText("Close Button Pressed"); } private void btnStopActionPerformed(ActionEvent evt) { lblStatusConnectDisconnect.setText("Stop Button Pressed");} private void btnListenActionPerformed(ActionEvent evt) { lblStatusConnectDisconnect.setText("Listen Button Pressed"); } public static void main(String args[]) { ServerGUI sg = new ServerGUI("Server"); sg.setVisible(true);}}

2. Change the status Label to display "Listening" and color it Green (this should be done in tilizes the GUI implemented in lablout (within the constructor of the ServerU class) as shown below: method of the ChatSever class). Server Status: Not Connected Status: Listening port # Port # Timeout Timeost Server Log Below Server Log Below Started Stop Qui Stop The purpose of the GUI is to control the ChatServer class (see ChatServer section below for a complete description) You will need to add the following private data field to the ServerGU class: The message "Server Started" should be displayed in the log TextArea by the senoerStarted hook method of the ChatServer class(see ChatServer section below) Pressing the Stop JButton (assuming Listen button has been previously pressed) will result in th following steps: private ShatSecvec, server; This server datafield should be instantiated within the SeerUI constructor using its default . Invoke the stopListewing service method on the ChatSeuver private data field (server). 2. Change the status JLabel to display "Stopped" and color it Red (this should be done in fthe user presses the Listen Button without the port# or timeout entered (both should be entered), display "Port Number/timeout not entered before pressing Listen" in the Server Log 3. The message "Server Stopped Accepting New Clients Press Listen to Start Accepting New Clients" should be displayed in the log TextAreg by the serverStopped hook method of the ChatServer class (see ChatServer section below). If the user presses the Close or Stop JButton before the server is successfully started (i.e., the Listen button has not been pressed), display "Server not currently started in the Server Log The stop service method prevents the Server from accepting any new clients. The previously accepted servers are however processed as before. The ServerGUI applications shuts down (and the GUI closes) if the user presses the Quit JButton at any time. An example of the GUI after pressing "Stop" is shown below Once the portii and timeout has been successfully entered into the GUI, pressing the Listen JButton results in the following: Invoke the listen service method on the ChatServer private data field (server). Server Server Status: Stopped Status: Close Port8300 Port Timeout Timeout Server Log Below Server Log Below Server Stopped Accecting New Clients-Press Listen to Start Accepting New and al current dients are dlosed-Press Listen to Restart Listen CloseSIop Quit Pressing the Close JButton (assuming Listen button has been previously pressed) will result in the following steps: ChatServer Invoke the close service method on the ChatServer private data field (server). 2. Change the status Label to display "Close and color it Red (the status Label should be Implement a class named ChatSeer (must extend AbstractServer)that implements the Server portion of the Chat System. The ChatServer should declare the following private data fields: changed in the ChatServers serverClosed method). 3. The message "Server and all current clients are closed Press Listen to private JTestAcea log; I/Corresponds to JTextacea of SecvecGu private abel status; //Corresponds to the 2habe, of SecxerGMA Restart" should be displayed in the log Textdrea by the sercverClosed hook method of the ChatSever class (see ChatServer section below) These 2 private dota fields are needed when updating the Srsrou fron within the Hooh methods of the Chatsecver class The close service method closes all clients currently connected to the server. The Server will need to press "Listen" to restart and begin accepting clients again. An example of the GUI after pressing "Close" JButton is shown below: Implement the following methods for the ChatSverclass public ChatSecvecC) Constructor for ChatServer class. Note: serverClosed and serverStopped methods are both invoked when the close method of the server is invoked. publie void setoz(sstAcsa log) Setter for TextArea originally declared and implemented in the ServerGUI class. This should be invoked within the Constructor of the SerxerGUI class. public void Setter for abel status area declared and implemented in the SenerGAZ class. This should be inoked within the Constructor of the ServerGUI class public void bandlelleaseseEconlieot object arge, SenosctianToClisot arg1) Slot method from AbstractServer class. For now, just display the following message to the Console: "Message from Client Received Hook method for ChaServer. Display the message Server and all current clients are closed-Press Listen to Restart" to the log . Also sets the Label, status to Close and is colored red. (See example shown previously) Hook method that is invoked whenever an Exception occurs while the ChatSsrvsr is in the process of accepting a client. Display the message associated with the parameter exception in the log TextArea of the ServerGUI whenever this method is invoked Hook method for ChatServer. For now, just display the message "client connected" to the log This method will be invoked when a non-Java client attempts to connect to the ChatServer For example, trying to connect a Web Browser to the ChatSeuver results in the following display: Server Status: Exception Occurred when Listoning port # Timeout Server Log Below Started Esception invalid stream header: 47455420 s Listen to Restart Server Stop Quit Also display the informational message that the user should press "Listen" again to restart the server. The status absl should also be set to "Exception Occurred when Listening" colored to red public void serveStacted) Hook method for Chasener. Display the message ..server Started" to the log Also sets the .absl status to Listening and is colored green. (See example shown previously) public void serusrStopped) Hook method for ChatServer Display the message "Server Stopped Accepting New Clients Press Listen to Start Accepting New Clients" to the log (Area. Also sets the status to Stopped and is colored red. (See example shown previously) public void sscyscClessd)

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

Recommended Textbook for

More Books

Students also viewed these Databases questions