Mavzu: Javafx yordamida tarmoq dasturini yaratish


Download 184.08 Kb.
Sana20.12.2022
Hajmi184.08 Kb.
#1036014

9-LABORATORIYA ISHI
Mavzu: JavaFX yordamida tarmoq dasturini yaratish
411-19 gurux Luqmonov Dilshod.

Server.java


package javafx;
import java.io.*;
import java.net.*;
class Server {

public static void main(String argv[]) throws Exception {


String clientSentence;
ServerSocket welcomeSocket = new ServerSocket(7777);
System.out.println("Server ishga tushdi!");
System.out.println("Kliyentdan so'rovni kutmoqda...");
while (true) {
Socket connectionSocket = welcomeSocket.accept();
System.out.println("Kliyent server bilan bog'landi");
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println("Server kliyentdan so'rovni qabul qildi");
System.out.println("Kliyentdan qabul qilingan matn:" + clientSentence);
outToClient.writeBytes(AreaOfRomb(clientSentence));
System.out.println("Server qabul qilingan so'rovni qayta ishlabkliyentga jo'natdi");
}
}

public static String AreaOfRomb(String str) {


String[] number = str.split("\\s+");
int x = Integer.parseInt(number[0]);
int y = Integer.parseInt(number[1]);
int z = Integer.parseInt(number[2]);

String natija;


int max;
if (x >= y && x >= z) // Returning 1st number if largest


{
max = x;
} // Comparing 2nd no with 1st and 3rd no
else if (y >= x && y >= z) // Return z if the above conditions are false
{
max = y;
} else // Returning 3rd no, Its sure it is greatest
{
max = z;
}

natija = Integer.toString(max);


return (natija) + "\n";


}
}

Client.java


package javafx;


import javafx.application.Application;
import javafx.event.*;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.io.*;
import java.net.*;

public class Client extends Application {


@Override


public void start(Stage stage) {
Text textA = new Text("1-sonni kiriting: ");
TextField textFieldA = new TextField();
Text textB = new Text("2-sonni kiriting");
TextField textFieldB = new TextField();
Text textC = new Text("3-sonni kiriting");
TextField textFieldC = new TextField();
Text text = new Text("Bu sonlarning eng kattasi: ");
TextField textField = new TextField();
Button button = new Button("Javob");
button.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
try (Socket clientSocket = new Socket("localhost", 7777)) {
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
String a = textFieldA.getText();
String b = textFieldB.getText();
String c = textFieldB.getText();
outToServer.writeBytes(a + " " + b + " " + c + '\n');
String area = inFromServer.readLine();

textField.setText(area);


} catch (IOException e) {
}
}
});
GridPane gridPane = new GridPane();
gridPane.setMinSize(400, 200);
gridPane.setVgap(20);
gridPane.setHgap(20);
gridPane.setAlignment(Pos.CENTER);

gridPane.add(textA, 0, 0);


gridPane.add(textFieldA, 1, 0);

gridPane.add(textB, 0, 1);


gridPane.add(textFieldB, 1, 1);

gridPane.add(textC, 0, 2);


gridPane.add(textFieldC, 1, 2);

gridPane.add(text, 0, 3);


gridPane.add(textField, 1, 3);

gridPane.add(button, 1, 4);


Scene scene = new Scene(gridPane);
stage.setTitle("Java FX Dastur");
stage.setScene(scene);
stage.show();
}

public static void main(String args[]) {


launch(args);
}
}




Download 184.08 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling