{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CH13 - Chapter 13 Applets and HTML HTML Applets Chapter 13...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Chapter 13 HTML Applets Applets and HTML
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Overview Applets: Java programs designed to run from a document on the Internet HTML: Hypertext Markup Language » a language used to create Internet documents Applets run within an HTML document HTML documents are run by a web browser, e.g. » Netscape Navigator or » Microsoft Internet Explorer
Image of page 2
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Applets Applet: small application Applets are Java programs embedded in HTML documents » therefor they run in a browser that views the document They are a derived class of the class JApplet , which is derived from Applet. Applet is in turn derived from Panel. » therefor it is both a Container and Component JApplet class is in the Swing library so import javax.swing.*
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Placing  JApplet  in  the Class Hierarchy Class Abstract Class Key: If there is a line between two classes, then the lower class is a derived class of the higher class. AWT Object Component Container Window Panel Frame JApplet Applet Swing JApplet is part of Swing and inherits from the Applet class. The Applet class is older than JApplet and is not part of AWT or Swing.
Image of page 4
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Applet Basics When writing applets your list of import statements will usually look like this: import javax.swing.*; import java.awt.*; import java.awt.event.*; Applets do not normally have a main method
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Applet Basics Applets do not normally use constructors but they do use a method named init for similar purposes: » setting colors » adding buttons » adding text fields, etc. » the init method has no parameters Th HTML document takes care of sizing the applet Use a layout manager when defining an applet » use the setLayout method
Image of page 6
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Example: a Trivial Applet HelloApplet.java import javax.swing.*; import java.awt.*; // for Container class public class HelloApplet extends JApplet { public void init(); { Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JLabel myFirstLabel = new JLabel("Hello out there!"); contentPane.add(myFirstLabel); } } Defining an applet
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch Running an Applet One way to run an applet: » put the applet in an HTML document good practice is to name the HTML document the same as the applet, but with ".html" instead of ".java" » then run it using appletviewer » like javadoc , javac , and java , appletviewer comes with the JDK (Java Development Kit) Syntax: appletviewer Applet_File_Name.html Example: appletviewer FirstApplet.html
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern