Programming Language (JAVA) : Topic 1 - Applets
Programming Language (JAVA) : Topic 1 - Applets
Programming Language (JAVA) : Topic 1 - Applets
Topic 1 Applets
Presentation 2
Objectives
At the end of this presentation, you will be able to :
Write an applet program to print a text using applet class and its methods View an applet using a Web browser
Hands-On!
Program HelloJava.java prints the string hello in the applet window, which is contained in the browser window.
Execution of Applet
Applet Viewer
Appletviewer is a standard JDK tool used to run an applet program as a standalone application. A comment statement, containing the applet tag, is added to the java file.
Hands-On!
Program Welcome.java prints a string in an applet window using appletviewer.
<APPLET> tag
Syntax
Activity 6.11.1
Step 1: Open the file applet_view.java.
Step 2: Add the given comment at the end of the file.
appletviewer applet_view.java
Sample Applet
Hands-On!
Program add.java calculates the sum of two numbers and prints it in the applet window.
Activity 6.11.2
Step 1: Open A_11_2.java from Student data file. Step 2: Compile the above program. Step 3: Edit the code line 7 as public class
FirstApplet.
50.
Step 5: Save the program as FirstApplet.java. Step 6: Compile the Java program and save the .class file in the same directory.
Lab Exercise
1. Write an applet program to print your friends name as a string and display the applet window through the browser and applet viewer.
2. Write an applet program to print the difference between two numbers and display the applet window through browser.
Summary
In this presentation, you learnt the following
Applets created are subclasses of Applet class. All applets must import java.applet package. Applet class is contained in the java.applet package. The Applet class provides the necessary support for applets.
Assignment
1. Write an applet program to display the name of your school.