Skip to content

Commit 1113cf8

Browse files
committed
Implemented scene navigation
1 parent 505cdf8 commit 1113cf8

11 files changed

Lines changed: 153 additions & 17 deletions

File tree

src/main/java/sealey/javafxinventorysystem/AddPart.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package sealey.javafxinventorysystem;
22

3+
import javafx.event.ActionEvent;
34
import javafx.fxml.FXML;
5+
import javafx.fxml.FXMLLoader;
46
import javafx.fxml.Initializable;
7+
import javafx.scene.Parent;
8+
import javafx.scene.Scene;
59
import javafx.scene.control.Button;
610
import javafx.scene.control.Label;
711
import javafx.scene.control.RadioButton;
812
import javafx.scene.control.TextField;
913
import javafx.scene.control.ToggleGroup;
14+
import javafx.stage.Stage;
1015

16+
import java.io.IOException;
1117
import java.net.URL;
18+
import java.util.Objects;
1219
import java.util.ResourceBundle;
1320

1421
public class AddPart implements Initializable {
22+
Stage stage;
23+
Parent scene;
1524
@FXML
1625
private ToggleGroup addpartgroup;
1726

@@ -51,6 +60,24 @@ public class AddPart implements Initializable {
5160
@FXML
5261
private Button saveButton;
5362

63+
@FXML
64+
void onActionCancel(ActionEvent event) throws IOException {
65+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
66+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
67+
stage.setScene(new Scene(scene));
68+
stage.show();
69+
}
70+
71+
@FXML
72+
void onActionCompanyLabel(ActionEvent event) {
73+
System.out.println("Change machine id label to company name");
74+
}
75+
76+
@FXML
77+
void onActionSave(ActionEvent event) {
78+
System.out.println("Save button pressed");
79+
}
80+
5481
@Override
5582
public void initialize(URL url, ResourceBundle resourceBundle) {
5683
System.out.println("initialized");

src/main/java/sealey/javafxinventorysystem/AddProduct.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package sealey.javafxinventorysystem;
22

3+
import javafx.event.ActionEvent;
34
import javafx.fxml.FXML;
5+
import javafx.fxml.FXMLLoader;
46
import javafx.fxml.Initializable;
7+
import javafx.scene.Parent;
8+
import javafx.scene.Scene;
59
import javafx.scene.control.Button;
610
import javafx.scene.control.TableColumn;
711
import javafx.scene.control.TableView;
812
import javafx.scene.control.TextField;
13+
import javafx.stage.Stage;
914

15+
import java.io.IOException;
1016
import java.net.URL;
17+
import java.util.Objects;
1118
import java.util.ResourceBundle;
1219

1320
public class AddProduct implements Initializable {
21+
Stage stage;
22+
Parent scene;
1423

1524
@FXML
1625
private Button addButton;
@@ -75,9 +84,16 @@ public class AddProduct implements Initializable {
7584
@FXML
7685
private TableColumn<?, ?> table2PriceCol;
7786

87+
@FXML
88+
void onActionCancel(ActionEvent event) throws IOException {
89+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
90+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
91+
stage.setScene(new Scene(scene));
92+
stage.show();
93+
}
94+
7895
@Override
7996
public void initialize(URL url, ResourceBundle resourceBundle) {
8097
System.out.println("initialized");
8198
}
82-
8399
}

src/main/java/sealey/javafxinventorysystem/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class Main extends Application {
1111
@Override
1212
public void start(Stage stage) throws IOException {
13-
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("AddPart.fxml"));
13+
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("MainWindow.fxml"));
1414
Scene scene = new Scene(fxmlLoader.load(), 800, 400);
1515
stage.setTitle("Inventory Management System");
1616
stage.setScene(scene);

src/main/java/sealey/javafxinventorysystem/MainWindow.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
package sealey.javafxinventorysystem;
22

3+
import javafx.event.ActionEvent;
34
import javafx.fxml.FXML;
5+
import javafx.fxml.FXMLLoader;
46
import javafx.fxml.Initializable;
7+
import javafx.scene.Parent;
8+
import javafx.scene.Scene;
59
import javafx.scene.control.Button;
610
import javafx.scene.control.TableColumn;
711
import javafx.scene.control.TableView;
812
import javafx.scene.control.TextField;
13+
import javafx.stage.Stage;
914

15+
import java.io.IOException;
1016
import java.net.URL;
17+
import java.util.Objects;
1118
import java.util.ResourceBundle;
1219

1320
public class MainWindow implements Initializable {
21+
Stage stage;
22+
Parent scene;
23+
1424
@FXML
1525
private Button addPartButton;
1626

@@ -68,6 +78,57 @@ public class MainWindow implements Initializable {
6878
@FXML
6979
private TextField searchProductText;
7080

81+
@FXML
82+
void onActionAddPart(ActionEvent event) throws IOException {
83+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
84+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("AddPart.fxml")));
85+
stage.setScene(new Scene(scene));
86+
stage.setTitle("Add Part");
87+
stage.show();
88+
}
89+
90+
@FXML
91+
void onActionAddProduct(ActionEvent event) throws IOException {
92+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
93+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("AddProduct.fxml")));
94+
stage.setScene(new Scene(scene));
95+
stage.setTitle("Add Product");
96+
stage.show();
97+
}
98+
99+
@FXML
100+
void onActionDeletePart(ActionEvent event) {
101+
System.out.println("Delete Part");
102+
}
103+
104+
@FXML
105+
void onActionDeleteProduct(ActionEvent event) {
106+
System.out.println("Delete Part");
107+
}
108+
109+
@FXML
110+
void onActionExit(ActionEvent event) {
111+
System.exit(0);
112+
}
113+
114+
@FXML
115+
void onActionModifyPart(ActionEvent event) throws IOException {
116+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
117+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("ModifyPart.fxml")));
118+
stage.setScene(new Scene(scene));
119+
stage.setTitle("Modify Part");
120+
stage.show();
121+
}
122+
123+
@FXML
124+
void onActionModifyProduct(ActionEvent event) throws IOException {
125+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
126+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("ModifyProduct.fxml")));
127+
stage.setScene(new Scene(scene));
128+
stage.setTitle("ModifyProduct");
129+
stage.show();
130+
}
131+
71132
@Override
72133
public void initialize(URL url, ResourceBundle resourceBundle) {
73134
System.out.println("initialized");

src/main/java/sealey/javafxinventorysystem/ModifyPart.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package sealey.javafxinventorysystem;
22

3+
import javafx.event.ActionEvent;
34
import javafx.fxml.FXML;
5+
import javafx.fxml.FXMLLoader;
46
import javafx.fxml.Initializable;
7+
import javafx.scene.Parent;
8+
import javafx.scene.Scene;
59
import javafx.scene.control.Button;
610
import javafx.scene.control.Label;
711
import javafx.scene.control.RadioButton;
812
import javafx.scene.control.TextField;
913
import javafx.scene.control.ToggleGroup;
14+
import javafx.stage.Stage;
1015

16+
import java.io.IOException;
1117
import java.net.URL;
18+
import java.util.Objects;
1219
import java.util.ResourceBundle;
1320

1421
public class ModifyPart implements Initializable {
22+
Stage stage;
23+
Parent scene;
1524

1625
@FXML
1726
private Button cancelButton;
@@ -52,6 +61,14 @@ public class ModifyPart implements Initializable {
5261
@FXML
5362
private Button saveButton;
5463

64+
@FXML
65+
void onActionCancel(ActionEvent event) throws IOException {
66+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
67+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
68+
stage.setScene(new Scene(scene));
69+
stage.show();
70+
}
71+
5572
@Override
5673
public void initialize(URL url, ResourceBundle resourceBundle) {
5774
System.out.println("initialized");

src/main/java/sealey/javafxinventorysystem/ModifyProduct.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package sealey.javafxinventorysystem;
22

3+
import javafx.event.ActionEvent;
34
import javafx.fxml.FXML;
5+
import javafx.fxml.FXMLLoader;
46
import javafx.fxml.Initializable;
7+
import javafx.scene.Parent;
8+
import javafx.scene.Scene;
59
import javafx.scene.control.Button;
610
import javafx.scene.control.TableColumn;
711
import javafx.scene.control.TableView;
812
import javafx.scene.control.TextField;
13+
import javafx.stage.Stage;
914

15+
import java.io.IOException;
1016
import java.net.URL;
17+
import java.util.Objects;
1118
import java.util.ResourceBundle;
1219

1320
public class ModifyProduct implements Initializable {
21+
Stage stage;
22+
Parent scene;
1423

1524
@FXML
1625
private Button addButton;
@@ -75,9 +84,16 @@ public class ModifyProduct implements Initializable {
7584
@FXML
7685
private TableColumn<?, ?> table2PriceCol;
7786

87+
@FXML
88+
void onActionCancel(ActionEvent event) throws IOException {
89+
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
90+
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
91+
stage.setScene(new Scene(scene));
92+
stage.show();
93+
}
94+
7895
@Override
7996
public void initialize(URL url, ResourceBundle resourceBundle) {
8097
System.out.println("initialized");
8198
}
82-
8399
}

src/main/resources/sealey/javafxinventorysystem/AddPart.fxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<ToggleGroup fx:id="addpartgroup" />
3333
</toggleGroup>
3434
</RadioButton>
35-
<RadioButton fx:id="outsourcedRadio" layoutX="271.0" layoutY="9.0" mnemonicParsing="false" text="Outsourced" toggleGroup="$addpartgroup">
35+
<RadioButton fx:id="outsourcedRadio" layoutX="271.0" layoutY="9.0" mnemonicParsing="false" onAction="#onActionCompanyLabel" text="Outsourced" toggleGroup="$addpartgroup">
3636
<font>
3737
<Font name="Arial" size="11.0" />
3838
</font>
@@ -83,8 +83,8 @@
8383
</GridPane>
8484
<AnchorPane layoutY="256.0" prefHeight="35.0" prefWidth="500.0">
8585
<children>
86-
<Button fx:id="cancelButton" layoutX="373.0" layoutY="5.0" mnemonicParsing="false" text="Cancel" />
87-
<Button fx:id="saveButton" layoutX="304.0" layoutY="5.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="57.0" text="Save" />
86+
<Button fx:id="cancelButton" layoutX="373.0" layoutY="5.0" mnemonicParsing="false" onAction="#onActionCancel" text="Cancel" />
87+
<Button fx:id="saveButton" layoutX="304.0" layoutY="5.0" mnemonicParsing="false" onAction="#onActionSave" prefHeight="25.0" prefWidth="57.0" text="Save" />
8888
</children>
8989
</AnchorPane>
9090
</children>

src/main/resources/sealey/javafxinventorysystem/AddProduct.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
6262
</columnResizePolicy>
6363
</TableView>
64-
<Button fx:id="cancelButton" layoutX="226.0" layoutY="387.0" mnemonicParsing="false" text="Cancel" />
64+
<Button fx:id="cancelButton" layoutX="226.0" layoutY="387.0" mnemonicParsing="false" onAction="#onActionCancel" text="Cancel" />
6565
<Button fx:id="saveButton" layoutX="133.0" layoutY="387.0" mnemonicParsing="false" text="Save" />
6666
<Button fx:id="removeButton" layoutX="135.0" layoutY="353.0" mnemonicParsing="false" text="Remove Associated Part" />
6767
</children>

src/main/resources/sealey/javafxinventorysystem/MainWindow.fxml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<?import javafx.scene.layout.AnchorPane?>
99
<?import javafx.scene.text.Font?>
1010

11-
1211
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="800.0" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="sealey.javafxinventorysystem.MainWindow">
1312
<children>
1413
<AnchorPane prefHeight="70.0" prefWidth="800.0">
@@ -39,17 +38,17 @@
3938
<Font name="Arial Bold" size="11.0" />
4039
</font>
4140
</Label>
42-
<Button fx:id="addPartButton" layoutX="147.0" layoutY="228.0" mnemonicParsing="false" text="Add">
41+
<Button fx:id="addPartButton" layoutX="147.0" layoutY="228.0" mnemonicParsing="false" onAction="#onActionAddPart" text="Add">
4342
<font>
4443
<Font name="Arial" size="12.0" />
4544
</font>
4645
</Button>
47-
<Button fx:id="modifyPartButton" layoutX="193.0" layoutY="228.0" mnemonicParsing="false" text="Modify">
46+
<Button fx:id="modifyPartButton" layoutX="193.0" layoutY="228.0" mnemonicParsing="false" onAction="#onActionModifyPart" text="Modify">
4847
<font>
4948
<Font name="Arial" size="12.0" />
5049
</font>
5150
</Button>
52-
<Button fx:id="deletePartButton" layoutX="253.0" layoutY="228.0" mnemonicParsing="false" text="Delete">
51+
<Button fx:id="deletePartButton" layoutX="253.0" layoutY="228.0" mnemonicParsing="false" onAction="#onActionDeletePart" text="Delete">
5352
<font>
5453
<Font name="Arial" size="12.0" />
5554
</font>
@@ -80,17 +79,17 @@
8079
<Font name="Arial Bold" size="11.0" />
8180
</font>
8281
</Label>
83-
<Button fx:id="addProductButton" layoutX="147.0" layoutY="228.0" mnemonicParsing="false" text="Add">
82+
<Button fx:id="addProductButton" layoutX="147.0" layoutY="228.0" mnemonicParsing="false" onAction="#onActionAddProduct" text="Add">
8483
<font>
8584
<Font name="Arial" size="12.0" />
8685
</font>
8786
</Button>
88-
<Button fx:id="modifyProductButton" layoutX="193.0" layoutY="228.0" mnemonicParsing="false" text="Modify">
87+
<Button fx:id="modifyProductButton" layoutX="193.0" layoutY="228.0" mnemonicParsing="false" onAction="#onActionModifyProduct" text="Modify">
8988
<font>
9089
<Font name="Arial" size="12.0" />
9190
</font>
9291
</Button>
93-
<Button fx:id="deleteProductButton" layoutX="253.0" layoutY="228.0" mnemonicParsing="false" text="Delete">
92+
<Button fx:id="deleteProductButton" layoutX="253.0" layoutY="228.0" mnemonicParsing="false" onAction="#onActionDeleteProduct" text="Delete">
9493
<font>
9594
<Font name="Arial" size="12.0" />
9695
</font>
@@ -108,7 +107,7 @@
108107
</AnchorPane>
109108
<AnchorPane layoutY="350.0" prefHeight="50.0" prefWidth="800.0">
110109
<children>
111-
<Button fx:id="exitButton" layoutX="639.0" layoutY="14.0" mnemonicParsing="false" prefHeight="23.0" prefWidth="51.0" text="Exit">
110+
<Button fx:id="exitButton" layoutX="639.0" layoutY="14.0" mnemonicParsing="false" onAction="#onActionExit" prefHeight="23.0" prefWidth="51.0" text="Exit">
112111
<font>
113112
<Font name="Arial" size="12.0" />
114113
</font>

src/main/resources/sealey/javafxinventorysystem/ModifyPart.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</GridPane>
8484
<AnchorPane layoutY="256.0" prefHeight="35.0" prefWidth="500.0">
8585
<children>
86-
<Button fx:id="cancelButton" layoutX="373.0" layoutY="5.0" mnemonicParsing="false" text="Cancel" />
86+
<Button fx:id="cancelButton" layoutX="373.0" layoutY="5.0" mnemonicParsing="false" onAction="#onActionCancel" text="Cancel" />
8787
<Button fx:id="saveButton" layoutX="304.0" layoutY="5.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="57.0" text="Save" />
8888
</children>
8989
</AnchorPane>

0 commit comments

Comments
 (0)