Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
denis-selimovic committed Mar 30, 2020
2 parents 8e72012 + fc872b4 commit 65f67d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
22 changes: 17 additions & 5 deletions src/main/java/ba/unsa/etf/si/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import ba.unsa.etf.si.controllers.LoginFormController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

Expand All @@ -23,11 +25,14 @@ public class App extends Application {
public void start(Stage stage) throws IOException {
primaryStage = stage;
primaryStage.initStyle(StageStyle.UNDECORATED);
Scene scene = new Scene(loadFXML(), 800, 600);
stage.setScene(scene);
stage.setTitle("Cash Register App");
stage.getIcons().add(new Image("/ba/unsa/etf/si/img/appIcon.png"));
stage.show();
primaryStage.setResizable(false);
primaryStage.setTitle("Cash Register App");
primaryStage.getIcons().add(new Image("/ba/unsa/etf/si/img/appIcon.png"));

Scene scene = new Scene(loadFXML());
centerStage(800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}


Expand All @@ -36,6 +41,13 @@ private Parent loadFXML() throws IOException {
return fxmlLoader.load();
}

public static void centerStage(int width, int height) {
primaryStage.setWidth(width);
primaryStage.setHeight(height);
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
primaryStage.setX((primScreenBounds.getWidth() - primaryStage.getWidth()) / 2);
primaryStage.setY((primScreenBounds.getHeight() - primaryStage.getHeight()) / 2);
}

public static void main(String[] args) {
launch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ private void startApplication(User loggedInUser) {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("fxml/primary.fxml"));
fxmlLoader.setControllerFactory(c -> new PrimaryController(loggedInUser));
Scene scene = new Scene(fxmlLoader.load());

Screen screen = Screen.getPrimary();
Rectangle2D rect = screen.getBounds();
primaryStage.setWidth(rect.getWidth());
primaryStage.setHeight(rect.getHeight());
Rectangle2D bounds = screen.getVisualBounds();
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
primaryStage.setWidth(bounds.getWidth());
primaryStage.setHeight(bounds.getHeight());

primaryStage.setScene(scene);
primaryStage.setMaximized(true);
primaryStage.setResizable(false);
primaryStage.centerOnScreen();
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ public void showMenu() {
public void logOut() {
try {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("fxml/loginForm.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 800, 600);
primaryStage.setWidth(scene.getWidth());
primaryStage.setHeight(scene.getHeight());
Scene scene = new Scene(fxmlLoader.load());
App.centerStage(800, 600);
primaryStage.setScene(scene);
primaryStage.setMaximized(false);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 65f67d4

Please sign in to comment.