1

My GUI is made by Netbeans Manager. Im trying to modify JComponents in my Frame that has a JTabbedPane:

System

When te user logged in. I need to set some Data in JTextFields with the UserData , and Enable some JTabbedPane tabs according its profile.

Im using ActionEvent in my loginButton to do my app login:

private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {
  //I have a DAO that Return a Object with the DB retrieved data
  UserDAOConcrete userDAO = UserDAOFactory.getUserDAO("user");
  Users userData =  userDAO.login(Integer.parseInt(loginUserId.getText()),   String.valueOf(userLoginPassword.getPassword()));
  //And then passing JComponents/param to a method to "configure" my JFrame
   int getItemsInCostCenter =  InventoryDAO.getInventory(userData.getUserCencos());
  //Class: GUI to deal with JComponents behaviour
  GUI.configGUIByUser(tranferTabGroup, userData, getItemsInCostCenter);
}

Method:

public static void configGUIByUser(JTabbedPane tabs, Users userData, int itemsInCostCenter) throws NullPointerException {

    if (itemsInCostCenter == 0) {
        tabs.setEnabledAt(1, false);
        tabs.setEnabledAt(0, true);
        tabs.setSelectedIndex(0);
        JOptionPane.showMessageDialog(null, "No se encontraron Elementos en Cencos: " + userData.getUserCencos(), cf.WINDOW_TITLE, JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(null, "Bienvenido: " + userData.getUserName(), cf.WINDOW_TITLE, JOptionPane.INFORMATION_MESSAGE);
        tabs.setEnabledAt(0, false);
        JOptionPane.showMessageDialog(null, "Cargando Inventarios de Centro de Costo: " + userData.getUserCencos(), cf.WINDOW_TITLE, JOptionPane.INFORMATION_MESSAGE);
        tabs.setSelectedIndex(0);
    }

}

So my code is working as intended , but I dont know if Im doing fine. I have 2 questions: Im breaking some Programming practices?. And is there a way to access JComponents of my JFrame ? I tried some of the code here but , I still cant access JFrame Components from my GUI Class.

Thanks in advance for your help.

Community
  • 1
  • 1
  • 1
    It's a question of responsibility. Does the object you're passing the component to really have the responsibility to control/change it. It most cases, it's better to devices some kind of controller which defines the contract of allowed actions that any other object might be able to take against it (and what information it's willing to provide), this reduces the cohesion in your code, makes it easier to change and manage. Try think about what you might have to do if you decided to use a `CardLayout` instead of `JTabbedPane`, how much work would that take to get it to work? – MadProgrammer Jan 19 '17 at 20:47
  • 1
    As an [example](http://stackoverflow.com/questions/13871887/jtabbedpane-wont-change-panel-on-mouseclick/13872201#13872201) – MadProgrammer Jan 19 '17 at 20:53
  • @MadProgrammer Thanks for your answer. 1) Yes the Data Object will set some JTextfields values and Enable some Tabs. 2) JTextfields are going to be used later on the aplication in DB Inserts. 3) Object retrieved all the inventory in that office according to Office Id, then create JTables with a realtime filter (Working).I tried Cardlayout but I need to show a lot of Data in JTables and Modify his ´DefaultTableModel´ in realtime to create a Final JTable that will update the data base (Working). So I need space for the user and show the most information I can. – Juan Sebastian Osorio Jan 19 '17 at 23:40
  • @MadProgrammer I will try to use Cardlayout , actually I had all the components I need :). I found this tutorial [Here](http://stackoverflow.com/questions/21898425/how-to-use-cardlayout-with-netbeans-gui-builder) – Juan Sebastian Osorio Jan 20 '17 at 00:46
  • I'm not saying you have to use `CardLayout`, only that if you choose to change container management, how hard would it be to change your code, this is a good indication that you may have a bad design ;) – MadProgrammer Jan 20 '17 at 00:48
  • @MadProgrammer Ohh I see, by any means Im not a professional developer, but I have all the logic and the SQL Stuff working (Over 4000 Lines of code) in Classes and DAO Implementations/Interfaces so Im trying to do my program with the best practices and Design Patterns I can, and not end with "Spaguetti" code and a button doing so many stuff with Methods (Even is working fine). Thanks for your appreciation. – Juan Sebastian Osorio Jan 20 '17 at 03:08

0 Answers0