Você está na página 1de 4

Atestare 2:

import javafx.animation.Animation;
import javafx.animation.FillTransition;
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;
import javafx.util.Duration;

import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class MainView extends Application {

private final List<Integer> numbers = new Random().ints(0, 100)


.limit(100)
.boxed()
.collect(Collectors.toList());

public static void main(String[] args) {


launch(args);
}

@Override public void start(Stage primaryStage) throws Exception {


FXMLLoader loader = new
FXMLLoader(MainView.class.getResource("/MainView.fxml"));
AnchorPane view = loader.load();
((MainController) loader.getController()).setNumbers(numbers);
primaryStage.setScene(new Scene(view));
primaryStage.show();

import javafx.animation.Animation;
import javafx.animation.FillTransition;
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.util.Duration;

import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

public class MainController {


public TextField number;
@FXML private Shape backgroundShape;
@FXML private AnchorPane pane;

private List<Label> labels;

@FXML private void initialize() {


ExecutorService service = Executors.newFixedThreadPool(4);
Thread th = new Thread(() -> changeBackground(backgroundShape));
th.setDaemon(true);
th.run();
}

public void setNumbers(List<Integer> numbers) {


Random random = new Random();
labels = numbers.stream()
.map(i -> new Label(i.toString()))
.peek(label -> label.relocate(
random.ints(0, 600).findFirst().getAsInt(),
random.ints(0, 400).findFirst().getAsInt()))
.collect(Collectors.toList());
labels.forEach(pane.getChildren()::add);
labels.forEach(label -> {
Thread thread = new Thread(() -> moveTask(label));
thread.setDaemon(true);
thread.start();
});
}

public void moveTask(Label label) {


Path path = new Path();
path.getElements().add(new MoveTo(100, 100));
path.getElements().add(new LineTo(100, 500));
path.getElements().add(new CubicCurveTo(380, 0, 380, 120, 200, 120));
path.getElements().add(new CubicCurveTo(0, 120, 0, 240, 380, 240));
PathTransition pathTransition = new PathTransition();
pathTransition.setDuration(Duration.millis(5000));
pathTransition.setPath(path);
pathTransition.setNode(label);

pathTransition.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
pathTransition.setCycleCount(Timeline.INDEFINITE);
pathTransition.setAutoReverse(true);
pathTransition.play();
}

public void changeBackground(Shape shape) {


final FillTransition ft = new FillTransition(Duration.millis(5000), shape,
Color.RED, Color.VIOLET);
ft.setAutoReverse(true);
ft.setCycleCount(Animation.INDEFINITE);
ft.play();
}

public void youCan(ActionEvent actionEvent) {


number.setText("Not, you can't!");
}
}

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.Rectangle?>

<AnchorPane fx:id="pane" prefHeight="400.0" prefWidth="600.0"


xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="MainController">
<children>
<Rectangle fx:id="backgroundShape" arcHeight="5.0" arcWidth="5.0"
fill="DODGERBLUE" height="400.0" layoutY="-1.0" stroke="BLACK" strokeType="INSIDE"
width="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<Button layoutX="197.0" layoutY="48.0" mnemonicParsing="false"
onAction="#youCan" text="Yes, I can!" />
<TextField fx:id="number" layoutX="14.0" layoutY="48.0" />
</children>
</AnchorPane>
2. Specificarea partii client la programarea in retea:

Conceptul de client este unul din cele mai importante concepte din programarea concurenta, alaturi de
conceptul de server.

Clientul reprezinta o abstractizare asupra tuturor programelor care se pot conecta la un canal de date,
prin care ulterior va comunica.

In programarea de retea, Clientul se conecteaza la un host, si un socket de retea pentru a putea


comunica cu lumea inconjuratoare.

Conectarea la un socket de retea se realizeaza prin intermediul clasei Socket. Comunicarea cu Serverul
de pe partea opusa se efectuiaza prin utilizarea buferelor de date incapsulate in clasa Socket.

Você também pode gostar