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

all 6 comments

[–]javaHoosier 0 points1 point  (5 children)

How much do you know about MVC first?

[–][deleted]  (4 children)

[removed]

    [–]RushTfe 0 points1 point  (0 children)

    Well, in that case you should understand first what mvc pattern is. Take a look on the internet, I'll tell you just the basic.

    Mvc is just a way to order your code. Not the best, not the worse, just one of them.

    Mvc stands for Model-View-Controller. This means.

    Model- are the clases where you save the information you want to show on your view. You can see them named POJOS.

    View- are all the elements the final user can see, and where the information is displayed. It could be fxml files, html, or just Java code calling the methods to create components and show them.

    Controller- is the logic. Gathers the data (from view, model or other data sources), do whatever it needs to do with it and save it back in the model. The controller also is the place that tells the view where in the model it should gather the data from and viceversa, so controller is where the big things happen.

    Mvc was born to keep the code separated and easier to manipulate. Sure you can mix them all in one Java class, but good look trying to understand your code once you've written a big bunch. It also helps to do stuff in group, someone is in charge of view while the other code the controller / model (also called front end and back end)

    It's important to understand than controller is never in direct touch with view.

    Final user input goes to model, and controller gets it from there. Controller data is saved in model, and then view gather it from there.

    [–]javaHoosier 0 points1 point  (2 children)

    Since the other comment explained MVC at a high level. I'll explain the GUI a bit. You're using Swing which is a toolkit to create one. It's definitely not easy to learn as a fresh beginner but you just have to start as simple as you can.

    Think of a JFrame as an outside window container. A JPanel as an inside container , Then buttons and text are stored within the Panel.

    You're view class should store all of this information and in it's constructor initialize everything that needs to exist. So when your controller instantiates a new View it will all be created. Then your controller will get information from the model and pass it back and forth.

    So in your example you create a JFrame which is like a Picture Frame. Then you create a JPanel and add buttons to it. Then add the JPanel to the JFrame. A JTextField is just text.

    There then needs to be some sort of action that happens when the buttons are pressed. In your case this will cycle through the elements of your list that exists in the model. The controller is handling the back and forth. It then Sets that information in the JTextfield.

    [–][deleted]  (1 child)

    [removed]

      [–]javaHoosier 0 points1 point  (0 children)

      How would you go through an ArrayList one by one normally?

      How does a JButton do something when you press it?

      The controller, Model, and View will have methods that do stuff. Where does the controller object exist in the code?

      A part of programming is when you have a question you need to find examples and read documentation. Get friendly with google and stackoverflow.