1 / 13

Applets and Course Evaluation

Applets and Course Evaluation. Applet Example - Sailing Applet UML Diagrams Applet Web Page Encoding (HTML) Applet Java Coding – Hello World Reading for this lecture: L&L 2.7-2.9, App G. Applet Use Case Diagram. Server Via Internet. Browser (Firefox). Scenario: Run Applet. Applet.

claire-odom
Download Presentation

Applets and Course Evaluation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Applets and Course Evaluation • Applet Example - Sailing • Applet UML Diagrams • Applet Web Page Encoding (HTML) • Applet Java Coding – Hello World • Reading for this lecture: L&L 2.7-2.9, App G

  2. Applet Use Case Diagram Server Via Internet Browser (Firefox) Scenario: Run Applet Applet

  3. Applet Class Diagram JApplet + init( ) : void + start( ) : void + stop( ) : void + destroy( ) : void AppletName Graphics + clearRect( … ) : void + setColor( … ) : void + drawString( … ) : void + drawRect( … ) : void (Override parent methods) + paint(screen : Graphics) : void

  4. Applet Sequence Diagram User Browser Server Open Page Obtain HTML file and Applet class file Display Page JApplet app = new JApplet(); app.init ( ) app.start ( ) app.paint (Graphics screen) Applet Display via calls to Graphics methods Close Page app.stop ( ) app.destroy ( ) app = null; (Garbage)

  5. JApplet Class • JApplet is a class in javax.swing package • It is a top level GUI container like a JFrame • Differences: • Not a standalone application – no main method • It is instantiated by an Internet browser • Browser calls the constructor: JApplet( ) • Browser controls the screen display • No JFrame methods such as: setSize() setVisible() setDefaultCloseOperation()

  6. Applet Web Page Coding (HTML) <HTML> <HEAD> <TITLE>Applet Name</TITLE> </HEAD> <BODY> <APPLET code=“AppletName" width=700 height=350> <PARAM NAME="Author" VALUE="Bob Wilson"> </APPLET> </BODY> </HTML>

  7. Applet Java Source Code import javax.swing.*; public class AppletName extends JApplet { public void init() // override { // called when browser loads Applet } public void start() // override { // called when Applet started/restarted }

  8. Applet Java Source Code public void stop() // override { // called when Applet is stopped } public void destroy() // override { // called when browser (tab) is closed } public paint(Graphics screen) // override { // called to paint/repaint the screen // e.g., when part of screen is uncovered } }

  9. Paint Method for “Hello World” public void paint (Graphics screen) { // look up/study the Graphics class methods // clear the Applet screen area screen.clearRect(0,0,this.getWidth(), this.getHeight()); // pick up a red pen for drawing screen.setColor(new Color(255,0,0)); // Ubiquitous “Hello World” in upper left screen.drawString(“Hello World!”, 0, 10); // and surround it with a rectangle screen.drawRect(0, 0, 100, 10); }

  10. Graphics Methods • Look carefully at the reference point for drawing something with each graphics method or you can have a problem Example: drawString(“Hello World”, 0, 0) • If drawn at 0,0: The text box will be above the visible area of the screen display Hello World! Visible Area of screen display (looks blank) Reference point is at lower left corner

  11. Graphics Methods • Use drawString (“Hello World!”, 0, 10) • But to surround the text with a rectangle, use drawRect(0, 0, … ) • If drawn at 0,10: The rectangle will be below the text – not around it. Hello World! Reference point is at upper left corner

  12. Applets in Local Files • You don’t need files stored on a server • You can store the HTML file and applet .class file on any local disk and the browser can open the file as a web page • The applet operates normally in the page • You can also run it in DrJava AppletViewer menu: Tools -> Run Document as Applet • The applet runs in an otherwise empty frame • Try it yourself in Lab 10

  13. Review for Exam 3 • Exam 3 is during next class • Practice exam is on-line • Prepare your crib sheet – 1 page, 2 sides • Review the text sections and lecture notes • Ask questions now or via email

More Related