Reputation: 21
I'm trying to make a text-based game and since I'm expecting to write a long code I decided to split it up into multiple files. (https://gist.github.com/Okkun9001/6d511dda544279a2c9d2e636b714a215) The "App" file would contain all the game related code, "MyFrame" to manage swapping between windows and possibly more GUI things down the line. Plus "HomePanel" and "GamePanel" in separate files, where both panels contains additional panels and more in the future.
Right now I have a button on HomePanel, and I want it to take me to "GamePanel", but actually MyFrame contains the method that would actually do that. And since my button is in HomePanel my MouseListener also needs to be there, but from HomePanel I cannot reference the method in MyFrame.
I also tried creating a reference to MyFrame in HomePanel, but I already created an instance of it in App, which can only be accessed from there. Also tried to move the MouseListener to MyFrame, which would make sense to have it there, but then it said that nothing is actually using it in that file, and to be honest I don't fully understand why that didn't work.
I was looking for more information about this online, but didn't find any specific example and I'm not sure what I should look for to further understand my problem.
Edit: I just noticed that I have a mistake in the uploaded files, in my original App.java at line 7 I actually say 'frame.buildHomePanel();'. Not that it changes anything, I was just trying to test things there.
Upvotes: 0
Views: 42