Topshiriq - 9-laboratoriya ishi mavzu: Javafx yordamida tarmoq dasturini yaratish Ishning maqsadi

Topshiriq:
Talaba laboratoriya ishi uchun shaxsiy topshiriq oladi. Bu topshiriq bo‘yicha
talaba TCP kliyent-server tarmoq dasturini JavaFX asosida yaratadi. Har bir talaba
uchun shaxsiy topshiriq 9.1-jadvalda keltirilgan.
9.1-jadval
Topshiriq variantlari
№
Topshiriq
1.
Matnni teskari tartibda
yozish
2.
N ta sondan musbatlari yig‘indisini
hisoblash
3.
N ta sonning yig‘indisini hisoblash
4.
Uchburchakning bissektrisa uzunligini topish
5.
Kubning hajmini topish
6.
N ta
sondan eng kichigini topish
7.
N ta sondan eng kattasini topish
8.
Sonning kvadrat ildizini hisoblash
9.
Sonni n darajaga ko‘tarish
10.
N ta sonni kamayish tartibida
saralash
6
Ishni bajarish tartibi:
1-qadam. Ish NetBeans IDE ishlab chiqarish muhitini yuklash bilan
boshlanadi. Buning uchun ish stolida turgan NetBeans IDE muhiti yorlig‘ini
sichqonchaning chap tomoni ikki marta bosiladi.
9.1-rasm. NetBeans IDE muhiti asosiy darchasi
11.
N ta sonni o‘sish tartibida saralash
12.
Koefitsentli kvadrat tenglama yechimini topish
13.
R radiusli doira
yuzini hisoblash
14.
R radiusli aylana uzunligini topish
15.
Uchburchakning yuzini hisoblash
16.
Rombning yuzini topish
17.
N ta sonning o‘rta arifmetigini hisoblash
18.
To‘g‘ri to‘rtburchakning yuzini topish
19.
N ta sonning o‘rta geometrigini hisoblash
20.
N ta sonning o‘rta arifmetigini topish
21.
N ta sonning o‘rta geometrigini topish
22.
N faktorialni topish
23.
N ta sondan juftlarini ajratib yozish
24.
Konus sirti yuzini topish
25.
R radiusli shar sirtining yuzini topish
26.
To‘g‘ri to‘rtburchak dioganalini hisoblab topish
27.
Silindr hajmini hisoblash
28.
R radiusli shar hajmini hisoblash
29.
Matnning toq o‘rindagi haflarini ajratib yozish
30.
Matnning juft o‘rindagi haflarini ajratib yozish
8
4-qadam. “New Класс Java” darchasining «Имя класса»
maydoniga
“Client”, «Пакет» maydoniga “javafx” kiritilib «Готово» tugmasi bosiladi.
5-qadam. Yaratilgan javafx paketi ichidagi Client.java fayliga quyidagi Java
kodi kiritiladi.
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.*;
import static javafx.application.Application.launch;
public class Client extends Application {
@Override
public void start(Stage stage) {
Text text = new Text("Matnni kiriting");
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", 7777)) {
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);
9
Scene scene = new Scene(gridPane);
stage.setTitle("Client");
stage.setScene(scene);
stage.show(); }
public static void main(String args[]) {
launch(args);
} }
9.4-rasm. NetBeans IDE muhiti Client.java
fayli
Client.java fayli yaratilgani kabi 3-5 qadamlar qayta bajarilib Server.java
fayli yaratiladi. Quyidagi Java kod Server.java fayliga kiritiladi.
package javafx;
import java.io.*;
import java.net.*;
class Server
{
public static void main(String argv[]) throws Exception
{
String clientSentence;
String capitalizedSentence;
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