Applications vs. Applets - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Applications vs. Applets

Description:

Applications vs. Applets. Applets run inside a browser. Applets almost always do something graphical (e.g. a stock ticker) ... The security in place does not ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 10
Provided by: mathew
Learn more at: http://www.cs.ucf.edu
Category:

less

Transcript and Presenter's Notes

Title: Applications vs. Applets


1
Applications vs. Applets
  • Applets run inside a browser.
  • Applets almost always do something graphical
    (e.g. a stock ticker)
  • The security in place does not allow applet to
  • Write files
  • Contact servers (other than the one that sent it)
  • Applications run outside a browser.
  • Applications typically are more full featured
    programs (e.g. word processors, IDEs (JBuilder is
    written in Java))
  • There are no security restrictions for
    applications.

2
Skeleton of an Application
  • package appvsapplet
  • public class MyLameApp
  • public static void main(String args)
  • System.out.println("Hello world!")

3
Skeleton of an Applet
  • package appvsapplet
  • import java.awt.
  • import java.applet.
  • public class MyLameApplet extends Applet
  • public void paint(Graphics g)
  • g.drawString("Hello world!", 20, 20)

4
Life cycle methods for an applet
  • init put code here that should be executed only
    once in the applets lifetime this method is
    called when the applet is first encountered
  • start put code here to start your applet
    called right after init or when user revisits
    page
  • stop put code here to stop your applet called
    when user leaves page containing applet
  • destroy put code here to relinquish resources
    many dont even use this method

5
Examples of life cycle code
  • init load images
  • start start an animation (usually with separate
    thread)
  • stop stop animation (by stopping the thread)
  • destroy close network connections

6
Life cycle methods (continued)
  • Browser calls these methods for you at
    appropriate times you just need to define what
    it does at those times
  • appvsapplet.MyLameApplet inherits from
    java.applet.Applet using the extends reserved
    word
  • Question Why doesnt MyLameApplet need to
    define init, start, stop, and destroy?

7
Applet Inheritance
  • MyLameApplet is not required to define life cycle
    methods since it INHERITS the implementation of
    those methods from java.applet.Applet
  • java.applet.Applets implementations of those
    methods do nothing!
  • So if you want them to do something, you must
    override those methods (more on this later)

8
Program 1
  • There are no objects explicitly instantiated in
    this program
  • Use only primitives (e.g. float) for this program
  • Find on the Internet how to convert Celsius value
    to Fahrenheit (you may hardcode the input (45)
    but not the output)
  • Youll need one more thing to finish

9
Methods of the String class
  • String.valueOf(myAnswer)
  • valueOf is a static method why?
  • valueOf can convert floats, ints, and others into
    String objects
  • Why do we care about this method?
  • Your calculated answer will be a float.
  • But there is no drawFloat method!
  • There is only a drawString method!
Write a Comment
User Comments (0)
About PowerShow.com