Hi there!
Here's the scenario:
+ Suppose we have a class GUI which extends JFrame and implements ActionListener.
+ We define a class Special_JPanel which extends JPanel.
+ A JComboBox, jCB, is a field in Special_JPanel.
+ A JPanel, baseJPnl, is a field in GUI.
+ A bunch of different components are placed into baseJPnl, including an instance of Special_JPanel.
+ The GUI class also functions as the driver class for my app.
The Problem:
+ A part of GUI's state needs to be dependent upon the ActionEvent which is generated by jCB ( e.g., If the user selects item 'a' from jCB, the GUI field 'm' is assigned value 'x', but if the user selects 'b' from jCB, 'm' is assigned value 'y'. )
The Current (Improper) Solution:
+ Set the access modifier of jCB to 'public' instead of 'private'. Then, it can be accessed directly from GUI.
The Query:
+ Aside form defining all of Special_JPanel within the body of GUI, is there a better way to solve this problem? I've been taught that the fields of a class must always be 'private' to maintain proper encapsulation.
Thanks in advance!
Chris