Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing's no prob, Java not so much
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chrisbrown




PostPosted: Sat Feb 10, 2007 7:31 pm   Post subject: 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
code:

procedure drawString (s : string)
    put s
end procedure

drawString ("Hello World")


makes perfect sense to me, I have trouble understanding how

code:

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
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sat Feb 10, 2007 7:41 pm   Post subject: 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




PostPosted: Sat Feb 10, 2007 7:52 pm   Post subject: Re: Turing's no prob, Java not so much

Quote:

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




PostPosted: Sat Feb 10, 2007 8:07 pm   Post subject: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: