Lépésszám kijelzése és menüpontok beállítása

This commit is contained in:
pp 2021-11-29 14:57:09 +01:00
parent 370e5c65bc
commit 17a6c9b10f
4 changed files with 73 additions and 14 deletions

View File

@ -7,7 +7,6 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Spinner;

View File

@ -1,18 +1,42 @@
package hanoi;
import java.io.Closeable;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class HanoiFormController {
private Korong kezbeKorong;
@FXML
private MenuItem ujItem;
@FXML
private MenuItem beallItem;
@FXML
private MenuItem kilepItem;
@FXML
private MenuItem helpItem;
@FXML
private ResourceBundle resources;
@ -34,6 +58,40 @@ public class HanoiFormController {
@FXML
private Pane felvettPane;
@FXML
private Label lepesCimke;
@FXML
void beallKattintas(ActionEvent event) {
}
@FXML
void helpKattintas(ActionEvent event) {
}
@FXML
void kilepkattintas(ActionEvent event) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Kilépés megerõsítése");
alert.setHeaderText("Ön a kilépés menüpontra kattintott.");
alert.setContentText("Valóban ki akar lépni a programból?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
// ... itt kell kilépni
//Platform.exit();
((Stage)jatekTerulet.getScene().getWindow()).close();
}
}
@FXML
void ujKattintas(ActionEvent event) {
}
@FXML
void elsoRudClick(MouseEvent event) {
korongMozgatas(r1);
@ -62,6 +120,8 @@ public class HanoiFormController {
if (r.addKorong(kezbeKorong)) {
kezbeKorong = null;
egyRudRajzolas(r);
fh.lepesNoveles();
lepesCimke.setText("Lépések száma: "+fh.getLepesSzam());
}
}
//rudRajzolas();

View File

@ -41,6 +41,7 @@
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hanoi.HanoiFormController">
<children>
@ -48,23 +49,16 @@
<menus>
<Menu mnemonicParsing="false" text="Fájl">
<items>
<MenuItem mnemonicParsing="false" text="New" />
<MenuItem mnemonicParsing="false" text="Open…" />
<Menu mnemonicParsing="false" text="Open Recent" />
<MenuItem fx:id="ujItem" mnemonicParsing="false" onAction="#ujKattintas" text="Új játék" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Close" />
<MenuItem mnemonicParsing="false" text="Save" />
<MenuItem mnemonicParsing="false" text="Save As…" />
<MenuItem mnemonicParsing="false" text="Revert" />
<MenuItem fx:id="beallItem" mnemonicParsing="false" onAction="#beallKattintas" text="Beállítások" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Preferences…" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Quit" />
<MenuItem fx:id="kilepItem" mnemonicParsing="false" onAction="#kilepkattintas" text="Kilépés" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Súgó">
<items>
<MenuItem mnemonicParsing="false" text="About MyHelloApp" />
<MenuItem fx:id="helpItem" mnemonicParsing="false" onAction="#helpKattintas" text="Használati útmutató" />
</items>
</Menu>
</menus>
@ -75,9 +69,14 @@
<Rectangle fx:id="masodikRudRect" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="303.0" layoutX="310.0" layoutY="81.0" onMouseClicked="#masodikRudClick" stroke="BLACK" strokeType="INSIDE" width="8.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="15.0" layoutY="384.0" stroke="BLACK" strokeType="INSIDE" width="640.0" />
<Rectangle fx:id="harmadikRudRect" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="303.0" layoutX="480.0" layoutY="81.0" onMouseClicked="#harmadikRudClick" stroke="BLACK" strokeType="INSIDE" width="8.0" />
<Pane fx:id="felvettPane" layoutX="133.0" layoutY="4.0" prefHeight="30.0" prefWidth="352.0">
<Pane fx:id="felvettPane" layoutX="133.0" layoutY="4.0" prefHeight="30.0" prefWidth="481.0">
<children>
<Label layoutX="13.0" layoutY="5.0" prefHeight="17.0" prefWidth="155.0" text="A felemelt korong:" />
<Label layoutX="13.0" layoutY="5.0" prefHeight="17.0" prefWidth="105.0" text="A felemelt korong:" />
<Label fx:id="lepesCimke" layoutX="325.0" layoutY="5.0" prefHeight="20.0" prefWidth="155.0" text="Lépések száma: 0">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
</children>
</Pane>
</children>

View File

@ -2,6 +2,7 @@ module HanoiTornyai {
requires javafx.controls;
requires javafx.fxml;
requires javafx.graphics;
requires javafx.base;
opens hanoi to javafx.graphics, javafx.fxml;
}