|
Talaba guruh: 416-20
|
tarix | 19.12.2023 | ölçüsü | 444,49 Kb. | | #184766 |
| Sayipov SH 9-labaratorya ishi
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
“Telekommunikatsiya texnologiyalari” fakulteti
FAN: Tarmoqni dasturlash asoslari
Laboratoriya ishi - 9
Talaba guruh:416-20
Bajardi: Sayipov Sharifjon
Tekshirdi: Abdullaev Ulug’bek
Toshkent 2023
9-LABORATORIYA ISHI
Mavzu: JavaFX yordamida tarmoq dasturini yaratish
18. To‘g‘ri to‘rtburchakning yuzini topish
Dastur kodi:
SHarifjon, [24.11.2023 19:49]
package com.example.demo1;
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 text = new Text("To‘g‘ri to‘rtburchakning yuzini topish");
TextField textField = new TextField();
Button button = new Button("Jo‘natish");
button.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
try (Socket clientSocket = new Socket("localhost", 8888)) {
DataOutputStream outToServer = new
DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
String a = textField.getText();
outToServer.writeBytes(a + '\n');
String b = inFromServer.readLine();
textField.setText(b); }
catch (IOException e){} } });
GridPane gridPane = new GridPane();
gridPane.setMinSize(400, 200);
gridPane.setVgap(5);
gridPane.setAlignment(Pos.CENTER);
gridPane.add(text, 0, 1);
gridPane.add(textField, 0, 2);
gridPane.add(button, 0, 3);
Scene scene = new Scene(gridPane);
stage.setTitle("Client");
stage.setScene(scene);
stage.show(); }
public static void main(String args[]) {
launch(args);
} }
SHarifjon, [24.11.2023 19:49]
package com.example.demo1;
import java.io.*;
import java.net.*;
import java.util.Arrays;
class Server {
public static void main(String argv[]) throws Exception {
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(8888);
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 -----------------\n" + " Doira dadusini kiriting:" + clientSentence);
String[] s = clientSentence.split(" ");
double S=Integer.parseInt(s[0])*Integer.parseInt(s[1]);
capitalizedSentence = " " +S + '\n';
outToClient.writeBytes(capitalizedSentence);
System.out.println("Server qabul qilingan so‘rovni qayta ishlabkliyentga jo‘natdi");
}
}
}
Dostları ilə paylaş: |
|
|