Sign in to follow this  
The C modest god

[java] I dont get it, how does it works?

Recommended Posts

I have written a java program. One of the classes has main and it only creates with new three objects. So basically there is no loop in the main so the main exists. The same thing with the constructors of the objects created in the main. They dont have any loops in them and the ctr exists. So how is the program managed? The program runs a small window with buttons and etc... When does the objects of the window are run? who runs them? I understand that even though the object I created finish running the ct'r they remain in the memory because someone points to them. What code is run after the ctr ends? and who called this code to run? Thanks in advance.

Share this post


Link to post
Share on other sites
Well, this has to do with Java Swing and AWT. The AWT system uses callbacks as an event handling model. This stuff all happens when you create a Frame or JFrame. The Frame or JFrame keeps track of everything within itself in a Collection. The Frame also handles painting itself.

So the short version is basically that there is a LOT of code behind a JFrame. You'll notice that JFrame is, like, a 7th-generation subclass of Component... it is built atop a ton of code which handles all the looping and polling and event-handling and such.

Share this post


Link to post
Share on other sites
Oh no, everything is executed sequentially, always.

When you have a window that is just sitting there, there is still code being sequentially executed somwhere within JFrame. You can always trace the exact sequence of lines that are executed by following the constructors and method calls of classes. If you had the code to JFrame sitting in front of you, you could do just that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this