applets yong choi school of business csu, bakersfield

12
Applets Yong Choi School of Business CSU, Bakersfield

Upload: luke-banks

Post on 05-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Applets Yong Choi School of Business CSU, Bakersfield

Applets

Yong ChoiSchool of BusinessCSU, Bakersfield

Page 2: Applets Yong Choi School of Business CSU, 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

Page 3: Applets Yong Choi School of Business CSU, Bakersfield

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

Page 4: Applets Yong Choi School of Business CSU, Bakersfield

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

Page 5: Applets Yong Choi School of Business CSU, Bakersfield

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>

Page 6: Applets Yong Choi School of Business CSU, Bakersfield

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

Page 7: Applets Yong Choi School of Business CSU, Bakersfield

Refer to the Java API for detail information

Page 8: Applets Yong Choi School of Business CSU, Bakersfield

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

Page 9: Applets Yong Choi School of Business CSU, Bakersfield

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…..

Page 10: Applets Yong Choi School of Business CSU, Bakersfield

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

Page 11: Applets Yong Choi School of Business CSU, Bakersfield

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)

Page 12: Applets Yong Choi School of Business CSU, Bakersfield

Complete Applet and GUI

Part 5: Applets and Graphics Part 8: Graphical User Interface Programming