Ok, For Instance I have a main class which extends JFrame like the below one; and also this class create an object of another class called Adjust.
public class Gui extends JFrame{
public Gui(){
... // There are some codes
Adjust adjust = new Adjust();
int length = adjust.getLength();
}
public static void main(String[] args){
Gui input = new Gui();
input.setVisible(true);
input.pack();
}
}
In Adjust Class, I need to have access to Gui class to get some information in order to produce the getLength method. In order to do that, I created an object of Gui class in Adjust class like the below one:
public class Adjust{
private int info;
public Adjust(){
Gui gui = new Gui();
this.info = gui.getInformation();
... // There are some additional codes
}
public int getLength(){
// in this method, I do some processes to provide the length based on information in gui
return ...
}
}
So, In adjust class, when I want to access Gui class, these classes repeatedly switch between them selves and are not moved to the next lines of codes. I also extends the Adjust class to Gui class, but it again happened and classes infinitely switches between each other. I do not want to create static instances and variables in Gui class in order to have direct access in Adjust class. Please help me where the problem is? If you feel there are some confusions in my explanation, please do let me know if I can make it better.
Here is more information. ==>I don't want to make the third class to combine the other two classes. The reason I want to do this, because I will use the Adjust object in other classes to access the getLength() method in Adjust class created based on the information in Gui class.