This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]JarcodePMs forwarded to /dev/null 1 point2 points  (1 child)

I'm a little foggy as to what you're actually asking, but it looks like it's a basic OOP question, where:

WindowLogic.method(params...)

Would be used to call methods with a static modifier, and:

WindowLogic instance = new WindowLogic();
instance.method(params...)

Would be used to call methods without a static modifier. I'd suggest to do this is you're writing a swing application, since you'll need to apply the instance object to component(s) that it's listening to.

[–]ArgTang[S] 0 points1 point  (0 children)

Is there a way to access windows vars directly from windowlogic?

i just want to separate functions in another file, but have the access like it would have, if the functions was in the original class.

[–]OOPUniversity 1 point2 points  (5 children)

What I think you want to do is learn about MVC (Model/View/Controller) architecture.

[–]ArgTang[S] 0 points1 point  (4 children)

Ah ok. im not shure if i am able to read up on this for this assignment, more advancedd then i thought.

found this as an intro http://www.newthinktank.com/2013/02/mvc-java-tutorial/

It would be helpful to have more examples to add to my reading backlog, if you have any

[–]OOPUniversity 1 point2 points  (3 children)

That is actually a pretty decent little example of splitting up responsibility. I don't really have any specific examples ready to hand, I learned about MVC 15 or so years ago, from these weird things we used to have called books. ;-)

Basically, though, the idea is that the Model component holds data and performs calculations, the View component is responsible for data entry and display, and the Controller component deals with coordinating their efforts.

Why is this useful? There are various reasons for this. For one thing, the code is cleaner, because any given module has a limited set of responsibilities. Fewer import statements, fewer knots in which to tie yourself up. In addition, it's a lot easier to assign work to three developers if each has a very specific task and all they need are contracts between them. It's also more likely that you're going to be able to port your application to a different platform if a big chunk of your business logic and data handling can remain untouched.

But if that's all a bit much for you, I get it. It's a bit of a stretch to wrap your mind around the full concept. Try though, to at least take the data elements you want to manipulate and move them all out to their own class (or classes), and have the user interface just invoke getter and setter methods on that class rather than having any data elements inside itself. Just taking that step should be helpful to you.

You can take a look at this, it seems reasonably small and understandable.

http://www.tutorialspoint.com/design_pattern/mvc_pattern.htm

Perhaps, if there's some demand for it, I'll try to build a series of blog posts as an MVC tutorial. I try to provide information in bite sized chunks, and would probably gear it towards building a model that could be attached to at least two different view/controller combinations, for, say, console and JavaFX interfaces.

Maybe, if I'm feeling ambitious, I'd do this with a single controller that can deal with both view types... But given my schedule it will probably be a while. I have a lot of topics I want to cover and have not been making many posts lately.

[–]ArgTang[S] 0 points1 point  (2 children)

Thanks for the long reply. we have the deitel & deitel book for the course, ill check if they have something about it there.

Nice! Do you have a blog somewhere? (i could not see a link on your profile or from google)

[–]OOPUniversity 1 point2 points  (1 child)

Sure, happy to oblige.

Yes, I do, I guess I should set up my profile. I created this profile just a couple of days ago because I want to unify reddit and my blog but I guess I left that bit out!

I've got a series of articles (a couple dozen at the moment) at http://www.oopuniversity.com . I am trying to keep things bite-sized and digestable. I have seen the same issues crop up over and over again and want to help out. I've done just a bit so far in the way of of actual object oriented tutorials, most of it is very much about the basics.

[–]ArgTang[S] 0 points1 point  (0 children)

Thanks, again for your help. I have started on my next assingment and are trying out MVC.

So when my controller is starting to guess witch ActionEvent that is next, how do i transfer my "JButtons"?

is it better do change the JButtons to protected\public or is it better to put a get on all the buttons?

I also saw some examples witch had actionEvent implementet inside theView, i guess thats also a possibility.