m06_un11_p02
TRANSCRIPT
-
8/3/2019 M06_UN11_P02
1/23
Programming Language (JAVA)
Unit 6.11 Applets
Presentation2
-
8/3/2019 M06_UN11_P02
2/23
Objectives
At the end of this presentation, you will be able to :
Write an applet program to print a text usingapplet class and its methods
View an applet using a Web browser
-
8/3/2019 M06_UN11_P02
3/23
Applet State Transition
-
8/3/2019 M06_UN11_P02
4/23
Hands-On!
ProgramHelloJava.java prints the stringhelloin the applet window, which is contained
in the browser window.
-
8/3/2019 M06_UN11_P02
5/23
The Applet Class
All the applets that are created should besubclasses of the Applet class.
Applet programs should import two packages,awt and applet.
-
8/3/2019 M06_UN11_P02
6/23
Class Inheritance of Applet Clas
-
8/3/2019 M06_UN11_P02
7/23
Execution of Applet
-
8/3/2019 M06_UN11_P02
8/23
Applet Viewer
Appletviewer is a standard JDK tool used torun an applet program as a standalone
application.
A comment statement, containing the applettag, is added to the java file.
-
8/3/2019 M06_UN11_P02
9/23
Hands-On!
Program Welcome.java prints a string in anapplet window using appletviewer.
-
8/3/2019 M06_UN11_P02
10/23
tag
Syntax/*
-
8/3/2019 M06_UN11_P02
11/23
Activity 6.11.1
Step 1: Open the file applet_view.java.
Step 2: Add the given comment at the end of
the file.
/*
*/
-
8/3/2019 M06_UN11_P02
12/23
Activity 6.11.1 (Contd..)
Step 3:Save the program.
Step 4:Compile the program.
Step 5:Run and observe the output byexecuting the program using applet vieweras
appletviewer applet_view.java
-
8/3/2019 M06_UN11_P02
13/23
Executing Applets Through HTML
Applets can also be viewed using a Webbrowser.
Steps to view an applet in a Web browser.
Step 1: Compile the java file.
Step 2: Include the applet tag in an HTML file.
Step 3: Open the HTML file in a Web browser.
-
8/3/2019 M06_UN11_P02
14/23
Web Page Template
-
8/3/2019 M06_UN11_P02
15/23
-
8/3/2019 M06_UN11_P02
16/23
Sample Applet
-
8/3/2019 M06_UN11_P02
17/23
Hands-On!
Program add.javacalculates the sum of two
numbers and prints it in the applet window.
-
8/3/2019 M06_UN11_P02
18/23
Activity 6.11.2
Step 1: OpenA_11_2.java from Student data file.
Step 2: Compile the above program.
Step 3: Edit the code line 7 aspublic classFirstApplet.
Step 4: Edit the code line 11 as Welcome, 150,50.
Step 5: Save the program as FirstApplet.java.
Step 6: Compile the Java program and save the.class file in the same directory.
-
8/3/2019 M06_UN11_P02
19/23
Activity 6.11.2 (Contd..)
Step 7:Type the following HTML code and save itas a.html.
1. 2.
3.
4.
5.
6.
-
8/3/2019 M06_UN11_P02
20/23
Activity 6.11.2 (Contd..)
Step 8: Replace the textA_11_2.class in line 3
with FirstApplet.class.
Step 9: Save the program.
Step 10: Run the HTML file in the browserwindow and observe the applet window.
-
8/3/2019 M06_UN11_P02
21/23
Lab Exercise
1. Write an applet program to print your friendsname as a string and display the applet
window through the browser and appletviewer.
2. Writean applet program to print the differencebetween two numbers and display the appletwindow through browser.
-
8/3/2019 M06_UN11_P02
22/23
Summary
In this presentation, you learnt the following
Applets created are subclasses of Appletclass.
All applets must importjava.appletpackage.Applet class is contained in thejava.appletpackage.
The Applet class provides the necessary supportfor applets.
All applets should also importjava.awtpackage.
-
8/3/2019 M06_UN11_P02
23/23