Package hud

Source Code of hud.HUD

package hud;

import bomb.Bomb;
import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import mainPac.World;
import plane.PlaneState;

public class HUD extends TitledPane{
   
    private Label timeLabel;
    private Button startButton;
    private Label livesLabel;
    private Hyperlink highScoresLink;
    private static final Image live = new Image(HUD.class.getResourceAsStream("live.png"));
    private ImageView liveView = new ImageView(live);
   
    public HUD(final World world){
        setText("BalsaWings2");
        timeLabel= new Label("0");
        startButton= new Button("Press to Start");
        startButton.setOnAction(new EventHandler<ActionEvent>(){
            @Override
            public void handle(ActionEvent t) {
                startButton.setDisable(true);
                world.init();
                world.getPlane().setState(PlaneState.FLYING);
                world.requestFocus();
            }
        });
        livesLabel= new Label("3");
        highScoresLink= new Hyperlink("High Scores");
        highScoresLink.setOnAction(new EventHandler<ActionEvent>(){
                @Override
                public void handle(ActionEvent t) {
                    world.getHighScoresPane().init();
                    world.getHighScoresPane().setTranslateX(world.getPlane().getTranslateX()-100);
                    world.getHighScoresPane().setVisible(true);
                }          
            });
        setContent(createBodyPane());
        setCollapsible(false);      
    }
   
    private VBox createBodyPane(){
        VBox body= new VBox();
        body.setPadding(new Insets(10,10,10,10));
        body.setSpacing(10);       
        if (!Platform.isSupported(ConditionalFeature.SCENE3D)) {
            body.getChildren().add(new Label("Your System does not support 3D graphics."));
        }
        else{                      
            HBox timebox= new HBox();
            timebox.setSpacing(10);
            timebox.getChildren().addAll(new Label("Score:"), timeLabel);
           
            HBox livesbox= new HBox();
            livesbox.setSpacing(10);
            livesbox.getChildren().addAll(liveView, new Label("X"), livesLabel);
           
            body.getChildren().addAll(timebox, livesbox, startButton, highScoresLink);
        }
        return body;
    }
   
    public void setTime(String time){
        timeLabel.setText(time);
    }

    public String getTime(){
        return timeLabel.getText();
    }
   
    public void setLives(String lives){
        livesLabel.setText(lives);
    }
   
    public Button getStartButton(){
        return startButton;
    }

}
TOP

Related Classes of hud.HUD

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.