1130tutorial9

1130tutorial9 - CSC1130 Introduction to Computer...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
    1 CSC1130 Introduction to Computer Programming Tutorial Notes 9
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    2 Outline Applet Single Entry, Single Exit  (IMPORTANT!) More on Assignment 5
Background image of page 2
    3 Introduction to Java Applet Applet means small application Application-let Java Applet is very similar to a normal Java  program http://java.sun.com/applets/
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    4 Introduction to Java Applet When we visit a web page, usually a HTML file  will be retrieved from the web server. The web browser displays the HTML page. <html> <head> <title>ABC </title> </head> <body> … … Web Server Local Computer
Background image of page 4
    5 Introduction to Java Applet When a web page contains an Applet, you have to first  download the class files from a web server. After all the required files have been downloaded, the  Java Virtual Machine inside the web browser will execute  the Applet in the local computer. Java Class Web Server Local Computer Execute…
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    6 How to write an Applet When you are writing an  Applet  class, you have  to extend the  java.applet.Applet  class. import java.applet.*; public class MyApplet extends Applet { } Import the java.applet package Remember to use public here The meaning of extending a class will be discussed later in lecture.
Background image of page 6
    7 How to write an Applet Execution of an  Applet  does not start in a  main()  method. There are several instance methods you have to  write in order to make the  Applet  work. public void init() It is invoked by the browser after the  Applet  is loaded  into the browser.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    8 How to write an Applet public void start() It is invoked by the browser when the browser starts the  execution of the  Applet public void stop() It is invoked by the browser when the browser stops the  execution of the  Applet . public void destroy() It is invoked by the browser when the browser shuts down  normally.
Background image of page 8
    9 How to write an Applet import java.applet.*; public class MyApplet extends Applet { public void init() { System.out.println(“Applet is loaded.”); } public void start() { System.out.println(“Applet is started.”); } public void stop() { System.out.println(“Applet is stopped.”); } public void destroy() { System.out.println(“Applet is destroyed.”); } }
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    10 The Life Cycle of an Applet Init Start Stop Destroy
Background image of page 10
    11 How to run an Applet? 1. Compile the Java source code. 2. Prepare an HTML file containing: <html> <head> <title>CSC1130 Assignment 5 - Hey That's My Fish</title> </head> <body> < applet code="HeyThatsMyFishApplet.class" width="581" height="487"> < /applet > </body> </html> The name of the Applet class file The dimension of the applet
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    12 How to run an Applet?
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 45

1130tutorial9 - CSC1130 Introduction to Computer...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online