applets yong choi school of business csu, bakersfield
TRANSCRIPT
Applets
Yong ChoiSchool of BusinessCSU, Bakersfield
What’s an Applet?
Applets- Programs that are called from within another application
You run applets on the Internet, an intranet, and an extranet a local computer from within another program called
Applet Viewer To view an applet, it should be called from within
another document written in HTML Visit Java API to see the applet package
Execution of an Applet
Applets are popular because users can execute them using a Web browser
Web browser: A program that allows you to display HTML documents on your computer screen
Internet Explorer Netscape Navigator
Understanding Simple Applets
To write an applet you must also: Include import statements to ensure that
necessary classes are available Learn to use some Windows components and
applet methods Learn to use the keyword extends
Writing an HTML Document to Host an Applet
Code to run an applet from within an HTML document (use the clip library of TextPad)
Need only two tags: <applet> </applet> but usually, programmers need to place three attributes within the <Applet> tag
For example<APPLET CODE = “MyApplet.class” WIDTH = 300 HEIGHT = 200></APPLET>
Attributes of an Applet Applet tag attributes
CODE = is followed by the name of the compiled applet you are calling
WIDTH = is followed by the width of the applet on the screen
HEIGHT = is followed by the height of the applet on the screen
The WIDTH and HEIGHT attributes are measured in pixels
Pixels: Picture elements, or tiny dots that make up the image on your video monitor
Refer to the Java API for detail information
Using Labels with Simple AWT Applets
The java.awt package contains commonly used Windows components such as:
Labels Menus Buttons
Label: Built-in class that holds text that you can display within an applet
Understanding Component and Container
Component- A class that defines any object that you want to display
Such as GUI component - Frames, panels, buttons, labels, and text fields
Container- A class that is used to define a component that can contain other components
Your browser is a container that contains buttons, labels, text fields…..
Understanding AWT Most AWT applets contain 2 import statements
import java.applet.*; import java.awt.*;
java.applet- Contains a class named Applet Every applet you create is based on Applet
java.awt- The Abstract Windows Toolkit, or AWT Used to be a package for GUI in Java 1.1
Understanding Simple Applets Most Swing applets contain 2 import statements
import javax.swing.*; import java.awt.*;
javax.swing- A package that contains classes that define GUI components (refer to as Swing components)
Complete Applet and GUI
Part 5: Applets and Graphics Part 8: Graphical User Interface Programming