1
I’m making a program (using the Netbeans GUI Builder and Cardlayout) with multiple screens (multiple Jpanels) and they’ll all have a start button, which obviously goes back to the home screen.
I want to make the code cleaner, so I created a new class, buttons.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 have the button run this method, it works normally as I expected, but netbeans indicates an error that is bothering me: "root has private access in Telaprincipal", where root is the main Jpanel (or parent) and Telaprincipal is the Jframe.
How do I fix it?
EDIT:
Part of the Telaprincipal 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();
}
It has how to include the code of the
TelaPrincipal
?– Renan Gomes
As I am using the Netbeans GUI Builder, the full Telaprincipal code is more than 300 lines (automatically generated, contains a lot of formatting and design only), but I tried to filter out the important part / that relates to the problem, edited the question and added it.
– pitalig
root = new javax.swing.
"root" is which object?– Renan Gomes
Oops! A thousand apologies! I just copied the code wrong, I fixed it! It’s a Jpanel...
– pitalig