HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Java Navigation System for GUI in JavaFX

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
systemnavigationjavaforguijavafx

Problem

I am currently working on a project in Java, and I use JavaFX for the GUI of the System. Currently, I am in the designing phase of the system, where I am designing the look of the system as well as setting up the basic functionality like navigation. I would highly appreciate it if someone can review my simple navigation system and the code I have written so far. I would like to know:

  • Any bad practices I am following, and how would I improve them.



  • Any architectural issues in my program, and how would I rectify that issue.



  • Any techniques I could follow to keep my software more maintainable.



  • Any inefficiencies that can be optimised.



  • And any sort of points you have in your mind that I could follow to improve my software.



  • Anything that you can add to the list above would also highly help.



I also have a preloader for this application, I have provided the code just for the sake of completeness. This preloader was generated by NetBeans.

TeleMart_Preloader.java

```
/*
* Program developed by Hassan Althaf.
* Copyright © 2015, Hassan Althaf.
* Website: http://hassanalthaf.com
*/
package telemart.preloader;

import javafx.application.Preloader;
import javafx.application.Preloader.ProgressNotification;
import javafx.application.Preloader.StateChangeNotification;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

/**
* Simple Preloader Using the ProgressBar Control
*
* @author hassan
*/
public class TeleMart_Preloader extends Preloader {

ProgressBar bar;
Stage stage;

private Scene createPreloaderScene() {
bar = new ProgressBar();
BorderPane p = new BorderPane();
p.setCenter(bar);
return new Scene(p, 300, 150);
}

@Override
public void start(Stage stage) throws Exception {
this.stage = stage;
stage.setScene(createPreloaderScene());
stage.show();
}

@Override
pub

Solution

No need to include class identifier

stage.setTitle(APPLICATION_TITLE);


Unhandled exception:

@FXML
        private void loginClick(MouseEvent event) {
            try {
                this.openDashboard();
            } catch (IOException exception) {

            }
        }


For your menu item handling, I really suggest using an enum instead of strings as identifiers.

String id = clickedItem.getId();

    switch (id) {
        case "homeMenuItem":
            this.changePage(this.home);
            break;
        case "anotherPageMenuItem":
            this.changePage(this.anotherPage);
            break;
        case "differentPageMenuItem":
            this.changePage(this.differentPage);
            break;
        default:
            this.changePage(this.home);
            break;
    }


https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

Also, you use this for non-static object referencing in situations where it's not necessary. You should only use this when you want to reference a non-static object's field that has the same name as a local variable.
https://stackoverflow.com/questions/3728062/what-is-the-meaning-of-this-in-java

Code Snippets

stage.setTitle(APPLICATION_TITLE);
@FXML
        private void loginClick(MouseEvent event) {
            try {
                this.openDashboard();
            } catch (IOException exception) {

            }
        }
String id = clickedItem.getId();

    switch (id) {
        case "homeMenuItem":
            this.changePage(this.home);
            break;
        case "anotherPageMenuItem":
            this.changePage(this.anotherPage);
            break;
        case "differentPageMenuItem":
            this.changePage(this.differentPage);
            break;
        default:
            this.changePage(this.home);
            break;
    }

Context

StackExchange Code Review Q#115108, answer score: 3

Revisions (0)

No revisions yet.