Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keeping gui and processing code seperate

 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making a little Notepad clone in Swing. Actually, I made it awhile ago but I had a class for each action event by buttons would throw. Each of them were nested in the same class as the gui. I thought this was bad practice so I'm trying to move them into their own class. I keep getting a StackOverflowError when I try and run my app now. I didn't know how I should have the Controller class see the gui items from my Layout class, so I just extended it. From this error, I don't think that was correct. Can anyone help me out here?
Layout.java

Controller.java
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do a stack trace
 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If anybody would try and run this, that would be awesome! Here is the output I get:
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason whi is your controller class.
WHy would you extned the layout class?
Your creating an action listener that executes some functions. make these methods and give a reference like COntainer parent; and add a set parent to them which you can probably reach some how
fix that and it will work. Your basically recursively creating both of the classes until your RAM runs out
 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I knew why I was getting the error, I'm just not sure how to fix it. The goal of extending the Layout class was so the Controller class could perform it's functions. Are the events normally in the same class or what?
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then create a layout class as a panel and keep al the other frame code separate
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is you are recursing everything
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic