点击按钮红点应闪烁

时间:2018-06-06 14:37:18

标签: java javafx

我有一个fontawesomeicon。如果我按下按钮btStar,红色圆圈应该在Fontawesomeicon上闪烁(请参阅GIF)。如果我按下按钮btStop,它应该被禁用。 我用标签试了一下。 当我按下按钮btStart时,标签会在SetVisible(true)setVisible(false)的时间间隔内发生变化。

enter image description here

有人能为我提供解决方案吗?先感谢您。 Main.java

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

Controller.java

package sample;

import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;

import java.awt.*;

public class Controller {

    @FXML
    private FontAwesomeIconView iconCamera;

    @FXML
    private Button btStart;

    @FXML
    private Button btStop;

    @FXML
    void mouseCklicked(ActionEvent event) {
        System.out.println("sad");

    }
}

sample.fxml

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

<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>


<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.141" fx:controller="sample.Controller">
   <columnConstraints>
      <ColumnConstraints />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints />
   </rowConstraints>
   <children>
      <AnchorPane prefHeight="387.0" prefWidth="573.0">
         <children>
            <FontAwesomeIconView fx:id="iconCamera" glyphName="VIDEO_CAMERA" layoutX="130.0" layoutY="123.0" size="36" />
            <Button layoutX="253.0" layoutY="93.0" mnemonicParsing="false" onAction="#mouseCklicked" text="Start" />
            <Button layoutX="354.0" layoutY="93.0" mnemonicParsing="false" text="Stop" />
         </children>
      </AnchorPane>
   </children>
</GridPane>

1 个答案:

答案 0 :(得分:1)

  • 创建没有红点的图像(PNG)。
  • 使用红点闪烁效果创建GIF。
  • 将两张图片导入您的项目。
  • 按开始时将图像设置为* .GIF。
  • 按下停止按钮将图像设置为* .PNG。

简单。不要让事情复杂化!

相关问题