Ishni bajarish tartibi:
Ishni NetBeans IDE ishlab chiqarish muhitini yuklash bilan boshlaymiz.
Buning uchun ish stolida turgan NetBeans IDE muhiti yorlig‘ini sichqonchaning
chap tomonini ikki marta bosib yuklaymiz. Bizning holatda NetBeans IDE muhiti
ishga tushadi.
6.
Ixtiyoriy n ta sondan eng kichigini topish
7.
Ixtiyoriy n ta sondan eng kattasini topish
8.
Ixtiyoriy sonning kvadrat ildizini hisoblash
9.
Ixtiyoriy sonni n darajaga ko‘tarish
10.
Ixtiyoriy n ta sonni kamayish tartibida saralash
11.
Ixtiyoriy n ta sonni o‘sish tartibida saralash
12.
Ixtiyoriy koefitsentli kvadrat tenglama yechimini topish
13.
Ixtiyoriy R radiusli doira yuzini hisoblash
14.
Ixtiyoriy R radiusli aylana uzunligini topish
15.
Uchburchakning yuzini hisoblash
16.
Rombning yuzini topish
17.
Ixtiyoriy n ta sonning o‘rta arifmetigini hisoblash
18.
To‘g‘ri to‘rtburchakning yuzini topish
19.
Ixtiyoriy n ta sonning o‘rta geometrigini hisoblash
20.
Ixtiyoriy n ta sonning o‘rta arifmetigini topish
21.
Ixtiyoriy n ta sonning o‘rta geometrigini topish
22.
Ixtiyoriy n faktorialni topish
23.
Ixtiyoriy n ta sondan juftlarini ajratib yozish
24.
Ixtiyoriy konus sirti yuzini topish
25.
R radiusli shar sirtining yuzini topish
26.
To‘g‘ri to‘rtburchak dioganalini hisoblab topish
27.
Ixtiyoriy silindr hajmini hisoblash
28.
R radiusli shar hajmini hisoblash
29.
Ixtiyoriy matnning toq o‘rindagi haflarini ajratib yozish
30.
Ixtiyoriy matnning juft o‘rindagi haflarini ajratib yozish
7
9.1- rasm. NetBeans IDE ishga tushish jarayoni
9.2- rasm. NetBeans IDE muhiti asosiy darchasi
Shundan so‘ng “Файл” menyusidan “Открыть проект” bo‘limi tanlanganda
paydo bo‘lgan darchadan “Talabaning_Ismi” loyihasini tanlab “Открытие
проекта” tugmasi bosiladi.
8
9.3- rasm. NetBeans IDE muhiti yangi klass yaratish
So‘ng ochilgan “Talabaning_Ismi” loyihasi ustiga sichqonchaning o‘ng
tumasi bir marta bosiladi, paydo bo‘lgan kontekst menyudan “Новый” → “Класс
Java” tanlanadi.
9.4- rasm. NetBeans IDE muhiti “New Класс Java” darchasi
“New Класс Java” darchasining «Имя класса» maydoniga “Client”,
«Пакет» maydoniga “javafx” kiritilib «Готово» tugmasi bosiladi.
Yaratilgan javafx paketi ichidagi Client.java fayliga quyidagi Java kodi
9
kiritiladi.
package javafx;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
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();
10
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);
}
}
11
9.5- rasm. NetBeans IDE muhiti Client.java fayli
Client.java fayli yaratilgan kabi 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
12
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);
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
System.out.println("Server qabul qilingan so'rovni qayta ishlab
kliyentga jo'natdi");
} } }
9.6- rasm. NetBeans IDE muhiti Server.java fayli
9.7- rasm. NetBeans IDE muhiti kliyent natijasi
13
9.8- rasm. NetBeans IDE muhiti server natijasi
Nazorat savollari
1.
java.net.* paketi
2.
java.io.* paketi
3.
javafx.stage.* paketi
4.
javafx.application.* paketi
5.
javafx.event.* paketi
http://hozir.org
Dostları ilə paylaş: |