Chapter 8 Frameworks Frameworks Framework is a set

  • Slides: 10
Download presentation
Chapter 8 Frameworks

Chapter 8 Frameworks

Frameworks ü Framework is a set of cooperating classes and interface types that structures

Frameworks ü Framework is a set of cooperating classes and interface types that structures the essential mechanisms of a particular domain. § Example: Swing is a GUI framework § Framework != design pattern § Typical framework uses multiple design patterns § Inversion of control: framework controls execution flow

Example of Frameworks Applets (1) ü Applet: Java program that runs in a web

Example of Frameworks Applets (1) ü Applet: Java program that runs in a web browser ü Programmer § forms subclass of Applet or JApplet § overwrites • • • Init start stop destroy paint

Example of Frameworks Applets (2) ü init § Called exactly once, when a class

Example of Frameworks Applets (2) ü init § Called exactly once, when a class that extends the Applet class. § Purpose: Initialize data structures and add user interface elements ü start § Called when the applet is first loaded and every time the user restore the browser window containing the applet. § Purpose: Start or restart thread that perform animation or other tasks.

Example of Frameworks Applets (3) ü stop § Called when the user hides the

Example of Frameworks Applets (3) ü stop § Called when the user hides the browser window containing the applet and when the browser terminates. § Purpose: Stop thread from updating the applet so computing resources are conserved when the applet is not being viewed. ü destroy § Called when the browser terminates. § Purpose: Relinquish any resources that were acquired during init or other processing.

Example of Frameworks Applets (4) ü paint § Called when the applet window needs

Example of Frameworks Applets (4) ü paint § Called when the applet window needs repainting. § Purpose: Redraw the window contents to reflect the current state of the applet data structures.

Example of Frameworks Applets (5)

Example of Frameworks Applets (5)

Example of Frameworks Applets (6) ü Sample Source Code: Shows scrolling banner ü HTML

Example of Frameworks Applets (6) ü Sample Source Code: Shows scrolling banner ü HTML page contains applet tag and parameters <applet code="Banner. Applet. class" width="300" height="100"> <param name="message" value="Hello, World!"/> <param name="fontname" value="Serif"/> <param name="fontsize" value="64"/> <param name="delay" value="10"/> </applet>

Example of Frameworks Applets (7) ü ch 8/applet/Banner. Applet. java ü ch 8/applet/Banner. Applet.

Example of Frameworks Applets (7) ü ch 8/applet/Banner. Applet. java ü ch 8/applet/Banner. Applet. html § init method reads parameters § start/stop start and stop timer § paints the applet surface

Example of Frameworks Applets (8)

Example of Frameworks Applets (8)