-
-
Save arthurlima96/0944984d5fb52754660f91f2b5c5cb20 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 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; | |
public class HomeGUI extends Application { | |
private AnchorPane pane; | |
private static Stage stage; | |
Button btJogar; | |
@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 : "); | |
TextField 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 { | |
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