How to minimize the usage of static variables and objects

Posted by Peter Penzov on Programmers See other posts from Programmers or by Peter Penzov
Published on 2013-06-26T08:17:19Z Indexed on 2013/06/26 10:28 UTC
Read the original article Hit count: 270

Filed under:
|

I'm trying to implement this JavaFX code where I want to call remote Java class and pass boolean flag:

final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
    toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
    {
        @Override
        public void handle(ActionEvent e)
        {

            //DataTabs.renderTab = toolbarSubMenuNavigation.isSelected();
            DataTabs.setRenderTab(toolbarSubMenuNavigation.isSelected());
            // call here the getter setter and send boolean flag
            System.out.println("subsystem1 #1 Enabled!");
        }
    });

Java class which I want to call:

public class DataTabs
{    
    private static boolean renderTab; // make members *private*
    private static TabPane tabPane;

    public static boolean isRenderTab()
    {
        return DataTabs.renderTab;
    }

    public static void setRenderTab(boolean renderTab)
    {
        DataTabs.renderTab = renderTab;
        tabPane.setVisible(renderTab);
    }

    // somewhere below
    // set visible the tab pane
    TabPane tabPane = DataTabs.tabPane = new TabPane();
    tabPane.setVisible(renderTab);
}

This implementation works but I want to optimize it to use less static variables and objects. Can you tell me which sections of the code how can be optimized?

© Programmers or respective owner

Related posts about java

Related posts about javafx