
-----------------------------------
chrisbrown
Sat Feb 10, 2007 7:31 pm

Turing's no prob, Java not so much
-----------------------------------
OK so I'm trying to teach myself Java coming from a strong background in Turing. While the program
 
procedure drawString (s : string)
    put s
end procedure

drawString ("Hello World")


makes perfect sense to me, I have trouble understanding how


import java.awt.*;
import java.applet.*;
         
public class HelloWorldApplet extends Applet {
            
    public void paint(Graphics g) {
        g.drawString("Hello World!", 10, 30);
    }
}


does essentially the same thing when there is no explicit call to the paint() method. I have more questions on the same topic but I'll put this out there to see if my answer pops up.

Thanks

-----------------------------------
wtd
Sat Feb 10, 2007 7:41 pm

RE:Turing\'s no prob, Java not so much
-----------------------------------
Well, when the Applet is loaded, the software handling it creates a new instance of it, and calls methods on it, including paint.

You may find it helpful to start with simpler code, if this is indeed your first introduction to Java.

-----------------------------------
chrisbrown
Sat Feb 10, 2007 7:52 pm

Re: Turing's no prob, Java not so much
-----------------------------------

Well, when the Applet is loaded, the software handling it creates a new instance of it, and calls methods on it, including paint.

When calling methods, how does the handler decide which methods to call? Obviously functions that return a non-void value would have no context to return a value to. Would I be correct in assuming these methods must be called explicitly by another method? As well, does the paint method require the handle paint, or could it be any legal identifier?

-----------------------------------
wtd
Sat Feb 10, 2007 8:07 pm

RE:Turing\'s no prob, Java not so much
-----------------------------------
The software that actually runs the Applet is designed to work with any class which is an Applet.  As your class extends Applet, it is an Applet.  

As such, that software is guaranteed that your class contains a certain set of methods, which includes paint.
