Created
December 23, 2018 01:00
-
-
Save arthurlima96/ca9a92dba97feafe578a531fcdb692f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ifma.dcomp.lp3.BatalhaNaval.view; | |
import ifma.dcomp.lp3.BatalhaNaval.model.Jogador; | |
import ifma.dcomp.lp3.BatalhaNaval.service.JogadorService; | |
import java.util.AbstractMap.SimpleEntry; | |
import java.util.Map.Entry; | |
import javafx.application.Application; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.geometry.Pos; | |
import javafx.scene.Scene; | |
import javafx.scene.control.*; | |
import javafx.scene.effect.DropShadow; | |
import javafx.scene.effect.Effect; | |
import javafx.scene.effect.Glow; | |
import javafx.scene.effect.SepiaTone; | |
import javafx.scene.image.Image; | |
import javafx.scene.image.ImageView; | |
import javafx.scene.input.KeyEvent; | |
import javafx.scene.layout.AnchorPane; | |
import javafx.scene.layout.HBox; | |
import javafx.scene.layout.VBox; | |
import javafx.scene.paint.Color; | |
import javafx.stage.Stage; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class HomeGUI extends Application { | |
private AnchorPane pane; | |
private static Stage stage; | |
private Button btJogar; | |
private TextField txJogador; | |
@Autowired | |
private JogadorService jogadorService; | |
@Override | |
public void start(Stage stage) throws Exception { | |
//initComponents(); | |
//initListeners(); | |
pane = new AnchorPane(); | |
pane.setPrefSize(300, 200); | |
Scene scene = new Scene(pane); | |
stage.setScene(scene); | |
stage.setResizable(false); | |
stage.setTitle("Batalha Naval"); | |
stage.show(); | |
initLayout(); | |
HomeGUI.stage = stage; | |
} | |
public static Stage getStage() { | |
return stage; | |
} | |
private void initLayout(){ | |
Label label = new Label("Jogador : "); | |
txJogador = new TextField(); | |
txJogador.setPromptText("Digite um nome"); | |
HBox hbox = new HBox(10,label, txJogador); | |
btJogar = new Button("Jogar"); | |
btJogar.setDisable(true); | |
Button btSair = new Button("Sair"); | |
pane.getChildren().addAll(hbox, btJogar, btSair); | |
hbox.setLayoutX(40); | |
hbox.setLayoutY(50); | |
btJogar.setLayoutX((pane.getWidth() - btJogar.getWidth()) / 2); | |
btJogar.setLayoutY(100); | |
btSair.setLayoutX((pane.getWidth() - (btSair.getWidth()+btJogar.getWidth()+100)) / 2); | |
btSair.setLayoutY(100); | |
btSair.setOnAction((event) -> { | |
fecharAplicacao(); | |
}); | |
btJogar.setOnAction(new EventHandler<ActionEvent>(){ | |
@Override | |
public void handle(ActionEvent event) { | |
iniciar_jogo(); | |
} | |
}); | |
txJogador.setOnKeyPressed(new EventHandler<KeyEvent>() { | |
@Override | |
public void handle(KeyEvent event) { | |
if(txJogador.getText().isEmpty()) | |
btJogar.setDisable(true); | |
else | |
btJogar.setDisable(false); | |
} | |
}); | |
} | |
public void iniciar_jogo(){ | |
try { | |
Jogador jogador = new Jogador(txJogador.getText()); | |
jogadorService.criar_jogador(jogador); | |
new Aplicacao().start(new Stage()); | |
HomeGUI.getStage().close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
private void fecharAplicacao(){ | |
System.exit(0); | |
} | |
// public static void main(String[] args) { | |
// HomeGUI.launch(args); | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment