Skip to content

Commit

Permalink
Update ClientGUI.java
Browse files Browse the repository at this point in the history
Fixed script
  • Loading branch information
Fedi6431 authored Jul 14, 2024
1 parent 152cbf4 commit a6b682e
Showing 1 changed file with 66 additions and 64 deletions.
130 changes: 66 additions & 64 deletions src/ClientGUI.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//This software is protected by Fedi6431© copyrights

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
Expand Down Expand Up @@ -40,24 +42,12 @@ public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
String address = textField.getText();
int port = 65000;
try {
ServerControlPanel(address, port);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Unable to connect to server", "Server login panel", JOptionPane.ERROR_MESSAGE);
int exitOption = JOptionPane.showConfirmDialog(null, "Want exit?", "Server login panel", JOptionPane.YES_NO_OPTION);
if (exitOption == JOptionPane.NO_OPTION) {
main();
} else if (exitOption == JOptionPane.YES_OPTION){
System.exit(1);
} else {
throw new RuntimeException(ex);
}
}
ServerControlPanel(address, port);
}
});
}

public static void ServerControlPanel(String address, int port) throws IOException {
public static void ServerControlPanel(String address, int port) {
// frame
JFrame serverFrame = new JFrame("Server control panel - LHE-Local_Host_Executer");
serverFrame.setSize(800, 500);
Expand Down Expand Up @@ -129,68 +119,80 @@ public static void ServerControlPanel(String address, int port) throws IOExcepti
// set the frame to visible
serverFrame.setVisible(true);

// establish a connection with the server
Socket socket = new Socket(address, port);
JOptionPane.showMessageDialog(null, "Connected successfully to the server", "Server login panel", JOptionPane.INFORMATION_MESSAGE);

// IP of the server and the client
String serverIP = socket.getLocalAddress().getHostAddress();
String clientIP = Inet4Address.getLocalHost().getHostAddress();

// get input from the terminal
BufferedReader ServerInfoOutput = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// send output to the server socket
DataOutputStream output = new DataOutputStream(socket.getOutputStream());

// strings to read inputs
String serverOS = ServerInfoOutput.readLine();
String os = serverOS;
String serverINFO = ServerInfoOutput.readLine();
String info = serverINFO;

// append the information of the server in the text area
textArea.append(info + "\n\n");
textArea.append("Server operating system: " + os + "\n");

final int[] stringUsed = {0};
submitbutton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// when the strings that are used are greater than 15 the client clear the text area
if (stringUsed[0] < 15) {
stringUsed[0]++;
} else if (stringUsed[0] >= 15) {
textArea.setText("");
textArea.append(info + "\n\n");
textArea.append("Server operating system: " + os + "\n\n");
for (int i=0;i < 15; i++) {
stringUsed[0]--;
try {
// establish a connection with the server
Socket socket = new Socket(address, port);
JOptionPane.showMessageDialog(null, "Connected successfully to the server", "Server login panel", JOptionPane.INFORMATION_MESSAGE);

// IP of the server and the client
String serverIP = socket.getLocalAddress().getHostAddress();
String clientIP = Inet4Address.getLocalHost().getHostAddress();

// get input from the terminal
BufferedReader ServerInfoOutput = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// send output to the server socket
DataOutputStream output = new DataOutputStream(socket.getOutputStream());

// strings to read inputs
String serverOS = ServerInfoOutput.readLine();
String os = serverOS;
String serverINFO = ServerInfoOutput.readLine();
String info = serverINFO;

// append the information of the server in the text area
textArea.append(info + "\n\n");
textArea.append("Server operating system: " + os + "\n");

final int[] stringUsed = {0};
submitbutton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// when the strings that are used are greater than 15 the client clear the text area
if (stringUsed[0] < 15) {
stringUsed[0]++;
} else if (stringUsed[0] >= 15) {
textArea.setText("");
textArea.append(info + "\n\n");
textArea.append("Server operating system: " + os + "\n\n");
for (int i = 0; i < 15; i++) {
stringUsed[0]--;
}
}
}

// append the commands in the text area
String line = textField.getText();
textArea.append(clientIP + " to " + serverIP + "$-" + line + "\n");
line = textField.getText();
// append the commands in the text area
String line = textField.getText();
textArea.append(clientIP + " to " + serverIP + "$-" + line + "\n");
line = textField.getText();
try {
output.writeUTF(line);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
});
});

EndSessionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0)
;
EndSessionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0)
;
}
});
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Unable to connect to server", "Server login panel", JOptionPane.ERROR_MESSAGE);
int exitOption = JOptionPane.showConfirmDialog(null, "Want exit?", "Server login panel", JOptionPane.YES_NO_OPTION);
if (exitOption == JOptionPane.NO_OPTION) {
serverFrame.setVisible(false);
Login();
} else if (exitOption == JOptionPane.YES_OPTION){
System.exit(1);
}
});

}
}

public static void main() {
public static void main(String[] args) {
Login();
}
}

0 comments on commit a6b682e

Please sign in to comment.