Download presentation
Presentation is loading. Please wait.
1
30 Java Applets
2
Previously Packages Structure Packages Views
3
Overview Java Applets Characteristics JApplet Methods Hello World
Applet Life Cycle Deployment
4
Lunch an Applet!
5
Characteristics Java Plug-in software in the browser manages the lifecycle of an applet Applets uses the browser services Web Server Storage Browser Library (y) OS Applet applet
6
JApplet JApplet class is in javax.swing package
Applets inherit significant functionality from the JApplet class Capabilities to communicate with the browser Capability to present a graphical user interface (GUI) to the user JApplet provides a root pane which is the same top-level component structure as JFrame
7
JApplet Inherit from JApplet Override method public void init()
Called when the applet is loaded into the browser
8
Methods init() start() stop() destroy()
Called when the applet is loaded into the browser start() Override if need to do some tasks after initialization stop() Should suspend the execution of the applet, so that it does not take up system resources when the user is not viewing the applet destroy() Perform all tasks necessary to shut down the applet stop() is called before destroy() so if overriding stop it may not be needed to override destroy
9
Hello World public class HelloWorldGUI extends JApplet {
/** * Hello World as a Java applet. * aasco */ public class HelloWorldGUI extends JApplet { * A version number for this class so that serialisation can occur without * worrying about the underlying class changing between serialisation and * deserialisation. * <br> * Not that we ever serialise this class of course, but JApplet implements * Serializable, so therefore by default we do as well. private static final long serialVersionUID = L; * Builds the GUI and adds the message. @Override public void init() { JLabel jlbHelloWorld = new JLabel(" Hello World!"); add(jlbHelloWorld); // add label to the GUI } // init() } // end class HelloWorldGUI
10
Applet Life Cycle When the page, where the applet is to appear, is displayed then an instance of the applet is created When leaving the page where the applet appear, e.g. to go to another page, the browser stops and destroys the applet
11
Applet Life Cycle When refresh or reload the page the applet appear in the browser, the current instance of the applet is stopped and destroyed and a new instance is created When closing the browser the applet has the opportunity of doing some cleanup
12
Deployment Compile code
Create JAR file with compiled code and resources Create the HTML page Use the Applet Tag inside the HTML page <applet code="com.aasco.fizbuz.gui.FizBuzApplet" archive="fizBuz.jar" width="900" height="500"> <param name="type" value="rnd" /> </applet> Place the JAR file and HTML page in the appropriate folder
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.