代码之家  ›  专栏  ›  技术社区  ›  Joe Mau

点击按钮红点应该会闪烁

  •  1
  • Joe Mau  · 技术社区  · 6 年前

    我有一个fontawesomeicon。如果我按下按钮 btStar btStop 它应该被禁用。 我试过贴标签。 当我按下按钮btStart时,标签在一个时间间隔内随着 SetVisible(true) setVisible(false) .

    enter image description here

    有人能给我一个解决办法吗?先谢谢你。 主类

    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);
        }
    }
    

    控制器.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");
    
        }
    }
    

    示例.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 回复  |  直到 6 年前
        1
  •  1
  •   Roshana Pitigala Laxmansinghsodhanohdiyala    6 年前
    • 创建一个没有红点的图像(PNG)。
    • 创建具有红点闪烁效果的GIF。
    • 将两个图像导入到项目中。
    • 按开始键时,将图像设置为*.GIF。
    • 按stop可将图像设置为*.PNG。

    很简单。别把事情搞复杂了!