Started making a simple GUI using netbeans and now I’m facing some problem.
I have this:
package my.sccsymapp;
public class sccsymapp extends javax.swing.JFrame {
/*SOME CODE*/
public static void main(String args[]) {
/*SOME CODE*/
}
// Variables declaration - do not modify
private javax.swing.JTextField tempmedespCost;
// End of variables declaration
}
If I run this, it works as expected. testis placed on my JTextField.
But what I want to do is to use tempmedespCost.setText("test"); in some other class of my code.
I have this class:
package my.sccsymapp;
import java.util.*;
public class Servico extends sccsymapp{
/*SOME CODE*/
public void relat (){
/*SOME CODE*/
tempmedespCost.setText("test");
}
/*SOME CODE*/
}
It now says:
tempmedespCost has private access in my.sccsymapp.sccsymapp
So I have changed tempmedespCost to public.
Now no error is shown, runs without errors but testis not placed on my JTextField.
Can you point me in some direction?
tempmedespCostis defined as private in your classprivatemembers can only be acceded by functions that are members of the class. Children of the class (likeServico) can’t access to private fields.You can either change the visibility of
tempmedespCostto protected or create a getter that will let you access totempmedespCostI suggest you read some documentation about Java visibility in Controlling Access to Members of a Class.