| Author |
Netbeans 4.0 - private/public access problem
|
Steve Schowiak
Greenhorn
Joined: Oct 21, 2002
Posts: 20
|
|
I want to change the text of a jLabel in another class at runtime from within a Java application. That class is declared as public: public class bank extends javax.swing.JPanel { ... I am getting this compile error: C:\Documents and Settings\Steve\J95\src\j95\main.java:18: bankJLabel has private access in j95.bank this.bank1.bankJLabel.setText("1"); This is the code in question: public main() { initComponents(); this.bank1.bankJLabel.setText("1"); // so on and so forth ... } NB 4.0 sets some variables as private at the bottom of the code in the main application class, but I'm not sure if this has anything to do with the problem: private j95.bank bank0; private j95.bank bank1; private j95.bank bank2; ... etc. The IDE won't let me change it to public so the jLabel can be accessed. I'm not sure if this is a problem with the IDE or me. Probably me . Can anybody offer a clue? The complete listing of the main application code follows. The application and other classes otherwise run fine. Thanks!:
|
I am not insane. The voices in my head told me so.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
Steve, I haven't used Netbeans, but their generated code is pretty clear. You definitely shouldn't mess with the generated code or it will not work in the future. Where is the "bank" class? Can you add a getter method to it? In general, it is better to use getter/setter methods than try to make the variables public. Also, two comments: 1) Class names are capital by convention. So "bank" should be "Bank". 2) Main is a bit confusing for a class name.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Steve Schowiak
Greenhorn
Joined: Oct 21, 2002
Posts: 20
|
|
I figured it out. If you right-click on the variable declarations at the bottom of the code, you can change public/private access. Thanks anyway!
|
 |
 |
|
|
subject: Netbeans 4.0 - private/public access problem
|
|
|