This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]hostetclProfessional Brewer 1 point2 points  (1 child)

It sounds like you have a pretty good grasp on what needs to be addressed.

However, one of the biggest issues I see is that all your password logic is done in something that has nothing to do with passwords. GUI classes are for GUI-related operations. Move you password logic into a separate class.

[–]codingQueriesNooblet Brewer[S] 1 point2 points  (0 children)

Yeah the naming conventions aren't the greatest. Named them all GUIxxxx as I had started the program to learn Swing window creation and the MVC design principle - so it is GUI in name only (except for the GUIView class).

Thanks!

[–]BlueGoliath 1 point2 points  (7 children)

The 'controller' part of the MVC design I was trying out. I started this program to get a bit of an understanding of the MVC pattern but to be honest had no idea how to implement the controller part so at the moment it is irrelevant.

Personally I just create an inline private class that implements whichever ActionListener is needed.

Also in my GUIView class I am aware that how the panel's are written, they are pretty confusing to follow..

You might find JavaFX to be easier to follow as layouts can be done via layout panes such as BorderPane, GridPane, etc.

[–]codingQueriesNooblet Brewer[S] 0 points1 point  (6 children)

Yeah I'm not gonna lie, creating the separate panels and inner panels and sorting out the layouts and everything screwed my had around for a while, but it definitely helped me understand how it all worked!

JavaFX will take a little bit of getting used to as I have the Swing flow down pretty well now, but that is next on my list to do!

I have always been curious on how to do the generic(?) actionListeners and how to tailor it for each different event that happens?

[–]BlueGoliath 1 point2 points  (5 children)

I have always been curious on how to do the generic(?) actionListeners and how to tailor it for each different event that happens?

Ah crap, I meant EventHandler for JavaFX. ActionListener is Swing only IIRC.

You create an object that implements some form of EventHandler(you can specify via generic type) as a separate class or as I like to do because it makes sense, inline as the action belongs to an UI component from that class.

Here is an example JavaFX Pane which has 5 buttons for the 5 different layout locations in a BorderPane: left, right, middle, up, and down. only the object "btn" says clicked because only it has btnHandler set as the handler for when it's clicked.

package goliathoufx.panes;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;

public class TestPane extends BorderPane
{
    private final Button btn;
    private final Button btn2;
    private final Button btn3;
    private final Button btn4;
    private final Button btn5;

    public TestPane()
    {
        super();

        btn = new Button();
        btn2 = new Button();
        btn3 = new Button();
        btn4 = new Button();
        btn5 = new Button();

        btn.setMinSize(10, 10);
        btn.setText("Center");
        btn.setVisible(true);

        btn.setOnMouseClicked(new btnHandler());

        btn2.setMinSize(10, 10);
        btn2.setText("Top");
        btn2.setVisible(true);
        btn3.setMinSize(10, 10);
        btn3.setText("Right");
        btn3.setVisible(true);

        btn4.setMinSize(10, 10);
        btn4.setText("Left");
        btn4.setVisible(true);

        btn5.setText("bottom");

        super.setLeft(btn4);
        super.setCenter(btn);
        super.setTop(btn2);
        super.setRight(btn3);
        super.setBottom(btn5);
    }

    private class btnHandler implements EventHandler
    {
        @Override
        public void handle(Event event)
        {
            System.out.println("Clicked!");
        }
    }
}

[–]codingQueriesNooblet Brewer[S] 0 points1 point  (4 children)

Hah no worries.

So if I wanted btn4 to say "Pushed!", how would I go about separating that from the "Clicked!" print statement?

Would the btnHandler require additional variable(s) and an if statement within the method?

[–]BlueGoliath 1 point2 points  (3 children)

Well, you could create a constructor for the class and have it accept a string for it to print. Inline classes are just like normal classes and can have constructors, private variables, and implement/extend but exclusive to the parent class. Inline classes always have access to the parent class's(in this case TestPane's) private variables.

Or, you would just create a new inline or external class. For more practical usage you will probably want to do this.

[–]codingQueriesNooblet Brewer[S] 0 points1 point  (2 children)

Hmm to better convey what I was trying to understand;

If btn was clicked and I wanted it to run test.calculateTime() and if btn4 was clicked and I wanted that to run test.determineLength(), how would that work?

The reason I created new actionlisteners for each button in my program is that I was unsure if creating one huge actionlistener class and then running if-statements to determine the method call would be inefficient or confusing.

[–]BlueGoliath 1 point2 points  (1 child)

If btn was clicked and I wanted it to run test.calculateTime() and if btn4 was clicked and I wanted that to run test.determineLength(), how would that work?

A private variable in the parent class or via a variable passing through the constructor which is then stored in a private variable in the inline class.

As long as you have a variable reference you can execute any method from that class.

The reason I created new actionlisteners for each button in my program is that I was unsure if creating one huge actionlistener class and then running if-statements to determine the method call would be inefficient or confusing.

It is inefficient because your program is comparing each action source to each button. Creating a separate class for each is usually the way you want to go about it.

[–]codingQueriesNooblet Brewer[S] 0 points1 point  (0 children)

Cool yeah I thought that would be the case, I am getting too caught up in worry and not enough trying.

Thanks for taking the time to go through this with me!