Applets and course evaluation
This presentation is the property of its rightful owner.
Sponsored Links
1 / 13

Applets and Course Evaluation PowerPoint PPT Presentation


  • 126 Views
  • Uploaded on
  • Presentation posted in: General

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.

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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

Applet Use Case Diagram

Server

Via

Internet

Browser

(Firefox)

Scenario:

Run Applet

Applet


Applet class diagram

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


Applet sequence diagram

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)


Japplet class

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()


Applet web page coding html

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>


Applet java source code

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

}


Applet java source code1

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

}

}


Paint method for hello world

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);

}


Graphics methods

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


Graphics methods1

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


Applets in local files

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


Review for exam 3

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


  • Login