1
+ package ru .shureck .java2020 .Lab11 ;
2
+
3
+ import javafx .application .Application ;
4
+ import javafx .application .Platform ;
5
+ import javafx .event .ActionEvent ;
6
+ import javafx .event .EventHandler ;
7
+ import javafx .fxml .FXML ;
8
+ import javafx .scene .Scene ;
9
+ import javafx .scene .control .Button ;
10
+ import javafx .scene .control .Label ;
11
+ import javafx .scene .control .TextField ;
12
+ import javafx .scene .layout .StackPane ;
13
+ import javafx .scene .text .Text ;
14
+ import javafx .stage .Stage ;
15
+ import javafx .stage .WindowEvent ;
16
+
17
+ import java .util .Random ;
18
+
19
+ public class Controller {
20
+
21
+ @ FXML
22
+ Text text1 ;
23
+ @ FXML
24
+ TextField text2 ;
25
+ @ FXML
26
+ Button ewe ;
27
+
28
+ public void initialize () {
29
+ text1 .setText ("Введите число" );
30
+ Random random = new Random ();
31
+ int s = random .nextInt (20 );
32
+ ewe .setOnAction (new EventHandler <ActionEvent >() {
33
+ @ Override
34
+ public void handle (ActionEvent actionEvent ) {
35
+ int k =0 ;
36
+ try {
37
+ k = Integer .parseInt (text2 .getText ());
38
+ if (k <s ){
39
+ text1 .setText ("Больше" );
40
+ text2 .setText ("" );
41
+ }
42
+ if (k >s ){
43
+ text1 .setText ("Меньше" );
44
+ text2 .setText ("" );
45
+ }
46
+ if (k ==s ){
47
+ Label secondLabel = new Label ("Вы угадали" );
48
+ Lab11 lab11 = new Lab11 ();
49
+ StackPane secondaryLayout = new StackPane ();
50
+ secondaryLayout .getChildren ().add (secondLabel );
51
+ Scene secondScene = new Scene (secondaryLayout , 230 , 100 );
52
+ text1 .setText ("Ура!" );
53
+ Stage newWindow = new Stage ();
54
+ newWindow .setTitle ("Ура!" );
55
+ newWindow .setScene (secondScene );
56
+ newWindow .setOnCloseRequest (new EventHandler <WindowEvent >() {
57
+ @ Override
58
+ public void handle (WindowEvent windowEvent ) {
59
+ newWindow .close ();
60
+ lab11 .close ();
61
+ }
62
+ });
63
+ newWindow .show ();
64
+ }
65
+ } catch (NumberFormatException e ) {
66
+ text1 .setText ("Введено не число" );
67
+ text2 .setText ("" );
68
+ }
69
+
70
+ }
71
+ });
72
+
73
+
74
+ }
75
+ }
0 commit comments