'Buttons action from multiple package in Java and Netbeans

I am making the login and register part of an app in Netbeans in Java and SQL. It is my first time using Netbeans and making a GUI with listeners etc.

I have a package app.controller a package app.view.

In my app.controller there is a class MainController.java, a class user.java and a class QueryRunner.java with a static function :

public static ResultSet runQuery(String query)

that runs a query by connecting to the data base with jdbc.

So in my user.java I can run a function :

public boolean login(String email, String password);

than return true if the user is present in the database and false if not. login uses runQuery in its body.

In theory in my MainController.java I want to instanciate a user and a QueryRunner and, a ButtonListener

In the app.view package, I have netbeans' automated JFrame with a form and a login button. When a person fill the form and press on login I need it to transfers to the MainController.java so it can handle everything.

To make this possible, my idea is that in the MainController.java I add a class MainView for example that comes from app.view. The problem is how to implement the listener ? And what to put in the Netbeans JFrame automatically generated code like this one for example:

 private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }   

Knowing that I will have many buttons later, like one to get reservation, another to delete reservation, and I want to handle them the same way :

button-click --> Listener Activate --> MainController.java getData from the View -->
class instanciated in MainController create and run SQL --> transfer to MainController.java --> update the View ...

While we are at it, am I correctly implementing MVC pattern ? My model being the dataBase ... I feel like I am doing something wrong because it simple but complicated at the same time... If you need more info don't hesitate to tell me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source