I'm doing a program (using the NetBeans GUI Builder and CardLayout) with several screens (various JPanels) and all of them will have a start button, which obviously returns to the home screen.
I want to leave the code cleaner, so I created a new class, botoes.java (already planning to use it for other buttons that should be repeated), and a method:
static void inicio(){
CardLayout c1 = (CardLayout) root.getLayout();
c1.show(root, "pInicio");
}
When I click the button to execute this method, it works normally, as I expected, but netbeans indicates an error that is bothering me: root has private access in MainPanel , where root is JPanel main (or parent) and MainPage is JFrame.
How do I resolve this?
EDIT:
Part of the Main Screen code:
root = new javax.swing.JPanel();
pInicio = new javax.swing.JPanel();
bInicio1 = new javax.swing.JButton();
root.setLayout(new java.awt.CardLayout());
root.add(pInicio, "pInicio");
private void bInicioActionPerformed(java.awt.event.ActionEvent evt) {
Botoes.inicio();
}