简体   繁体   中英

How to modify a private access object?

I made a frame and added a desktop pane (dp_1) to it. Then I created a separate internal jframe form (Inj) and assigned this code to a button in frame form (main).

Inj inj = new Inj();
dp_1.add(inj);
inj.setVisible(true);

It works fine. Then I created another internal jframe form(Inj_1). I want to set it visible by a button in Inj. I did trying the same code, but there comes an error.

Error is ;

error: dp_1 has private access in NewJFrame

* () include the variable name.

You should provide a public method in the class that owns that variable and let it modify its own state.

You can also use reflection if you must, but I don't recommend it.

You must be trying to use dp_1 outside the class in which it is defined.

SO the solution is to either increase its visibility by modifying access level to either default, protected or public

Or create a public method that returns dp_1 object from it and then access it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM