Designing web page: – Java applet uses web page for display output on screen. A web page is basically made up of text and HTML tag that can be interpreted by a web browser or an applet viewer. Like java source code, it can be prepared using any ASCII text editor. A web page is known as HTML page. Web page can be stored using file extension .HTML. Such files are referred to HTML files and it must be stored in the same directory as the compiled code of the applet.
A web page is marked by an opening HTML tag <HTML> and a closing HTML tag </HTML>. An HTML web page can be divided into three different groups namely comment section, head section and body section.
Comment section: – This section is optional and it contains comment about the web page. It is important to include comments that tell us what is going on in the web page. A comment line begins with a <! And Ends with>. Web browser will ignore the text enclosed between them. All though comments are important, they should be kept to a minimum as they will be downloaded along with the applet. Note that comment can be included anywhere in the web page.
Head section: – This section is optional and is defined with a starting <HEAD> tag and closing </HEAD> tag. This section usually contains a title for the web page. This title will have displayed as well as on the web page. Format of the head section is –
<HEAD> <TITLE> Welcome To Java Applet </TITLE> </HEAD>
The text enclosed in the tag <TITLE> and </TITLE> will appear in the title bar of the web browser windows when it is displayed the page.
Body section: – After the head section, the body section can be use. This section is mandatory because it contains entire information about the web page and its behavior. We can set up many options to indicate how our page must appear on the screen. The body section can be assign with <BODY> and </BODY> tag. Inside the body tag, number of other tags can also we use. We can put multiple tags for designing web page in the following format –
<HTML> <! This page includes a welcome title in the title bar and also displays a welcome message. Then it specifies the applet to be loaded and executed.> <HEAD> <TITLE> Welcome To Java Applets </TITLE> </HEAD> <BODY> <CENTER> <H1> Welcome To The World of Applets </H1> </CENTER> <BR> <CENTER> <APPLET CODE=HelloJava.class WIDTH=400 HEIGHT=200> </APPLET> </CENTER> </BODY> </HTML>