Ablak meghívása, felhasználó és korongszám átadása. Korongok generálása

megkezdve.
This commit is contained in:
pp 2021-10-18 14:52:24 +02:00
parent a5756c8deb
commit fdc2b18bd7
4 changed files with 74 additions and 5 deletions

View File

@ -1,13 +1,20 @@
package hanoi; package hanoi;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; 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.Button;
import javafx.scene.control.Spinner; import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory; import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class FoablakController { public class FoablakController {
@ -27,8 +34,24 @@ public class FoablakController {
private Button playGomb; private Button playGomb;
@FXML @FXML
void playGombAction(ActionEvent event) { void playGombAction(ActionEvent event) throws IOException {
String fnev = (nevMezo.getText()==null || nevMezo.getText().isEmpty()) ? "anonymous" : nevMezo.getText();
Felhasznalo fh = new Felhasznalo(fnev);
FXMLLoader fl = new FXMLLoader(getClass().getResource("hanoi_form2.fxml"));
VBox root = (VBox)fl.load();
Scene sc = new Scene(root);
Node n = (Node) event.getSource();
Stage st = (Stage) n.getScene().getWindow();
st.setScene(sc);
st.show();
// a felhasználó és korongszám átadása a hanoi ablaknak
HanoiFormController hfc = fl.getController();
hfc.setFh(fh);
hfc.setKorongokSzama(kspin.getValue());
} }
@FXML @FXML

View File

@ -4,13 +4,20 @@ import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
public class HanoiFormController { public class HanoiFormController {
@FXML @FXML
private ResourceBundle resources; private ResourceBundle resources;
@FXML
private AnchorPane jatekTerulet;
@FXML @FXML
private URL location; private URL location;
@ -29,7 +36,7 @@ public class HanoiFormController {
@FXML @FXML
void elsoRudClick(MouseEvent event) { void elsoRudClick(MouseEvent event) {
} }
@FXML @FXML
@ -48,6 +55,44 @@ public class HanoiFormController {
assert masodikRudRect != null : "fx:id=\"masodikRudRect\" was not injected: check your FXML file 'hanoi_form2.fxml'."; assert masodikRudRect != null : "fx:id=\"masodikRudRect\" was not injected: check your FXML file 'hanoi_form2.fxml'.";
assert harmadikRudRect != null : "fx:id=\"harmadikRudRect\" was not injected: check your FXML file 'hanoi_form2.fxml'."; assert harmadikRudRect != null : "fx:id=\"harmadikRudRect\" was not injected: check your FXML file 'hanoi_form2.fxml'.";
assert felvettPane != null : "fx:id=\"felvettPane\" was not injected: check your FXML file 'hanoi_form2.fxml'."; assert felvettPane != null : "fx:id=\"felvettPane\" was not injected: check your FXML file 'hanoi_form2.fxml'.";
r1 = new Rud(elsoRudRect);
r2 = new Rud(masodikRudRect);
r3 = new Rud(harmadikRudRect);
//fh = new Felhasznalo(null);
} }
private void korongGeneralas() {
//System.out.println(jatekTerulet.widthProperty());
korongSzelMax = jatekTerulet.getWidth()/3-2*KDIFF;
for (int i = 0; i < korongokSzama; i++) {
}
}
public void setFh(Felhasznalo fh) {
this.fh = fh;
System.out.println(fh.getNev());
}
public void setKorongokSzama(int korongokSzama) {
this.korongokSzama = korongokSzama;
korongGeneralas();
}
private Rud r1;
private Rud r2;
private Rud r3;
private Felhasznalo fh;
private int korongokSzama;
private double korongSzelMax;
final private double KDIFF = 30;
private Color[] szinek = {};
} }

View File

@ -69,7 +69,7 @@
</Menu> </Menu>
</menus> </menus>
</MenuBar> </MenuBar>
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS"> <AnchorPane fx:id="jatekTerulet" maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<children> <children>
<Rectangle fx:id="elsoRudRect" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="303.0" layoutX="140.0" layoutY="81.0" onMouseClicked="#elsoRudClick" stroke="BLACK" strokeType="INSIDE" width="8.0" /> <Rectangle fx:id="elsoRudRect" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="303.0" layoutX="140.0" layoutY="81.0" onMouseClicked="#elsoRudClick" stroke="BLACK" strokeType="INSIDE" width="8.0" />
<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 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" />

View File

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