Applets (Day 7 of, Java in 21 Days)
  21 Days:   Wk1 . Wk1Ref . Applts . Swing . Grph . D13-14 . D15-21 . D22-28
  cc12:   Miscl . SQL . EJB . Vocab . (NotesHelp) . J2EE . Web
  misl:   21 Days(src) . Dictionary(foldoc) . Unicode . Tables . Print . html
  misl:   F.Allimant . Swing (J.H.University)

-----Jul/25/2002 THU-FRI pg.163, "Day 7", Writing Java Applets. - Java introduced interative web pages, and is still effective. Macromedia Flash and Microsoft ActiveX can do similar things. (pg.163)
  How Applets and Applications Are Different.
-----Jul/25/2002 THU-FRI: - Applications run with a Java interpreter, Applets run on a browser that supports Java. - Applet testing may be done with the appletviewer tool in the SDK. - "For an applet to run, it must be included on a Web page using HTML tags in the same way images and other elements are included. When a user..." loads a Web page containing an applet, the browser downloads the applet from a web server before it runs. The interpreter is built into the browser. - Appropriate limitations, of Applets, on most browsers... 1. CAN'T read or write files on user's system. 2. CAN'T communicate w/ internet site other than site serving page of applet. 3. CAN'T run programs on user's system. 4. CAN'T load programs stored on user's system, like exe's or dll's. - "Appletviewer" does allow limited file access. - CAUTION: Get acquainted with known "hostile applets". (It is recomended to web search this topic.) (pg.165.nearBottom)
  Applet Security Restrictions.
-----Aug/13/2002 TUE: - "Java's current version includes a way for a Web user to trust an applet, so that applet can run without restriction on the user's system, just as an application can." Specific SECURITY (day.16) controls are available. ( ===Choosing a Java Version (pg.165.bottom) 1) Java 1.0 will run on all Java-capable browsers. 2) Java 1.1 for Netscape 4, Internet Explorer 4, Opera 3.6... (and higher). 3) Java 2 may be used if the Sun add-on called the "Java Plug-in" is installed. - Latest version of java is always supported on latest "Appletviewer" in the matching SDK. - Prior version's of java are fully documented at - (pg.185.paragrph4): Built into most browsers now, is a Java 1.1 interpreter. - Version 1.1 offers: an improved user interface, and better handling of events, and more.
  Creating Applets.
-----Aug/13-24/2002 TUE-SAT: (pggg.167) ===CREATING APPLETS - Java applications generally have a main() method. It creates objects, sets instance variables, and calls other methods. - Java applets do not have a main() method. They have several methods called at different points of the applet's execution. - All applets are subclasses of either the JApplet or the Applet class. JApplet supports swing. - Sample: public class myApplet extends javax.swing.JApplet { // applet code here } - Your primary applet class must be declared public, since JApplet is a public class. - The browser "calls methods of the JApplet class when specific events take place". (see:pg.167.bottom) ===Major Applet Activities (Aug/19/2002 MON) (pg.168) 1) Initialization - public void init() { /*code*/ } (pg.168) - sample /*code*/: setBackground(orange); // wont be shown until applet window is redrawn. 2) Starting - public void start() { /*code*/ } // start (?) or return to pg. (pg.169) 3) Stopping - public void stop() { /*code*/ } // when leave pg, or call to stop(). (pg.169) 4) Destruction - public void destroy() { /*code*/ } // often not overridden. (pg.170) - kill running threads, or release running objects. 5) Painting - public void paint(Graphics g) { /*code*/ } // display to screen (pg.170) - text, line, background, image, etc. - paint may run hundreds of times: when initialized, or browser brought from behind other window, different position... - "Graphics g" is an instance of class Graphics. It is created and supplied by the browser. - Needed: import of java.awt.Graphics, usually by import statment at top of your Java source. - Note: "*" used in w/import statement, does not include subclasses of the package. - if you need to force a call to paint, call repaint(); - if Graphics2D needed cast the "Graphics g" parameter. - most applet work is done inside paint();
  Including an Applet on a Web Page, the "APPLET" tag.
-----Aug/24/2002-Sep/04: "APPLET" TAG ANNND ITS ATTRIBUTES (pg.172-179) ===An Example Applet - Watch.html loads Watch.class applet compiled from - "APPLET" is just for applets. "OBJECT" can be used instead, and supports more. - Each of following are required: <applet code="Watch.class" height="50" width="445"> - Other attributes besides CODE, WIDTH, and HEIGHT are similar to IMG attributes. . ALIGN=LEFT, RIGHT, TEXTTOP, TOP, ABSMIDDLE, MIDDLE, BASELINE, ABSBOTTOM. - To end ALIGN, BR with CLEAR=LEFT, RIGHT, ALL. . HSPACE and VSPACE to set pixels between applet and text. - CODEBASE is optional and points to a different dir to find class files.
  Java Archives for Faster Download.
-----Sep/04/2002 WED: JAVA ARCHIVES (pggg.180) - "Jar" files can be used to speed loading of an applet when multiple files are involved. Without it, each file would need a separate conection. - Example of creating a jar file from command line...: jar cf Animate.jar *.class *.gif - Attribute to name this jar file is ARCHIVE="Animate.jar"
  Applet Parameters.
-----Oct/17/2002 THU: (pg.181-185) - Applications can get parameters from the command line into main(). - Applets can get parameters from the HTML file containing the applet. - Two things needed for applet parameters: 1) "A special parameter tag in the HTML file." 2) "Code in your applet to parse those parameters." - Example: <APPLET CODE="Watch.class" WIDTH="445" HEIGHT="50"> <PARAM NAME=font VALUE="TimesRoman"> <PARAM NAME=size VALUE="24"> Java Applet appears here. </APPLET> - In the init() method, getParameter() can be called. . public String getParameter(String parameterName) Returns of getParameter() is the value of the named parameter. . parameterName of getParameter() is case sensitive.
  Devloping Java 2 Applets, for Java Plug-in.
-----Oct/23/2002 WED: (page.185)<< - The Java Plug-in, is a virtual machine that improves a web browser's Java support. - Built into most browsers now, is a Java 1.1 interpreter, developed by the brower developer. - Version 1.1 offers: an improved user interface, and better handling of events, and more. - Sun offers a Java Plug-In that runs instead of the built in Java interpreter. For applet programmers who want to use the latest java language features. - To use the plug-in we need two things: 1) the browser needs the java plug-in installed, and 2) the html page must have html code to tell the java plug-in to run the applet. - Java Plug-In can be found: 1) within the SDK 1.3, or 2) download at ===Using the Plug-In on a Web Page (pg.186): - HTML written to tell the java plug-in to run, is considerably more complicated. - From the same web page where you can download the plug-in, you also find the HTMLConverter to convert standard html, to html that tells the java plug-in to run the applet. - After install, you should add the converter's path to your CLASSPATH (and re-boot). - Once installed, run as follows: java HTMLConverter YourApplet.html ===Running the Plug-In (Oct/30) (pg.187.bottom): - If the html specifies that the java plug-in is needed to run, 1) a check is made to see if it is already installed in the browser. 2) If it is not, the user will see a pop-up window asking for permision to install the plug-in from Sun Microsystems. - pg.188: Because the plug-in is so large, Sun recomends to programmers to write applets in java 1.1 or 1.0 for most purposes. And to reserve requiring the plug-in "for intranets, large-scale corporate software, and other projects where the audience is well defined." ===Summary (pg.189): - Applets are no longer the focus of Java development, but applets have the most end users. - The capability to use the graphics user interface, since displayed in web pages, gives applet programmers more features with less toil. - All applets are subclasses of java.applet.Applet or javax.swing.JApplet class. [ ]Q: How similar is an applet's init() method to a java aplications main() method? 99 percent similar? 85 percent? 75 percent? or less? // done chapter.
===Virtual Machine - (pg.18): a sort of computer-within-a-computer. - Java programs are compiled into machine code (called bytecode) for a virtual machine. The virtual machine interprets this bytecode by converting it into a specific processor's machine code. ******************************************************************************** B19 - Teach Yourself Java 2 in 21 Days. 2nd ed. Lemay and Cadenhead. © 2001. ********************************************************************************
Java Home