Java Code. Алексей Алексеевич Крючков

Чтение книги онлайн.

Читать онлайн книгу Java Code - Алексей Алексеевич Крючков страница 4

Java Code - Алексей Алексеевич Крючков

Скачать книгу

style="font-size:15px;">                           break;

                           case 3:

                               s="вторник";

                               break;

                               case 4:

                                   s="среда";

                                   break;

                                   case 5:

                                       s="четверг";

                                       break;

                                       case 6:

                                           s="пятница";

                                           break;

                                           case 7:

                                               s="суббота";

                                               break;

                                               default:

                                                   break;

               }

               return s;

           }

      Всплывающее сообщение как в Android(Toast)

      Этот метод можно встретить в вышеприведенных примерах. Попробуйте его в своих проектах и получите практически полную копию всплывающего сообщения как в android.

      void toast(String toastMsg){

              Stage toastStage=new Stage();

              toastStage.setResizable(false);

              toastStage.initStyle(StageStyle.TRANSPARENT);

              Text text = new Text(toastMsg);

              text.setFont(Font.font("Verdana", 20));

              text.setFill(Color.WHITE);

              StackPane root = new StackPane(text);

              root.setStyle("-fx-background-radius: 10; -fx-background-color: rgba(0, 0, 0, 0.2); -fx-padding: 20px;");

              root.setOpacity(0);

              Scene scene = new Scene(root);

              scene.setFill(Color.BLACK);

              toastStage.setScene(scene);

              toastStage.show();

              Timeline tl1 = new Timeline();

              KeyFrame fadeInKey1 = new KeyFrame(Duration.millis(500), new KeyValue (toastStage.getScene().getRoot().opacityProperty(), 1));

              tl1.getKeyFrames().add(fadeInKey1);   

              tl1.setOnFinished((ae) ->

              {

                  new Thread(() -> {

                      try

                      {

                          Thread.sleep(2000);

                      }

                      catch (InterruptedException e)

                      {

                          e.getMessage();

                      }

                         Timeline tl2 = new Timeline();

                          KeyFrame fadeOutKey1 = new KeyFrame(Duration.millis(500), new KeyValue (toastStage.getScene().getRoot().opacityProperty(), 0));

                          tl2.getKeyFrames().add(fadeOutKey1);   

                          tl2.setOnFinished((aeb) -> toastStage.close());

                          tl2.play();

                  }).start();

              });

              tl1.play();

          }

Скачать книгу