Java Applet Layout Implementations
Java Applet Layout Implementations
NO: 1
DATE:
FLOW LAYOUT
ALGORITHM:
1
PROGRAM:
import [Link].*;
import [Link].*;
2
OUTPUT:
Z:\>javac [Link]
Z:\>appletviewer [Link]
3
[Link]: 2
DATE:
BORDER LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”[Link]” and the
4
PROGRAM:
import [Link].*;
import [Link].*;
5
OUTPUT:
Z:\>javac [Link]
Z:\>appletviewer [Link]
6
[Link]: 3
DATE:
GRID LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”[Link]” and the
PROGRAM:
7
//program to demonstrate the grid layout
import [Link].*;
import [Link].*;
for(int i=0;i<12;i++)
{
add(new Button(""+i));
}
}
}
8
OUTPUT:
Z:\>javac [Link]
Z:\>appletviewer [Link]
[Link]: 4
9
DATE:
GRIDBAG LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”[Link]” and the
PROGRAM:
10
// program to demonstrate the gridbag layout
import [Link].*;
import [Link].*;
/*<applet code=gridbag height=300 width=300>
</applet>*/
public class gridbag extends Applet
{
public void init()
{
GridBagLayout gb =new GridBagLayout();
setLayout(gb);
GridBagConstraints gc=new GridBagConstraints();
Label l=new Label("States and Capitals");
[Link]=[Link];
[Link](l,gc);
add(l);
Label l1=new Label("Tamil Nadu");
add(l1);
Label l2=new Label("Goa");
add(l2);
Button b1=new Button("Chennai");
add(b1);
Button b2=new Button("Panaji");
add(b2);
[Link]=0;
[Link]=2;
[Link](l1,gc);
[Link]=1;
[Link]=2;
[Link](b1,gc);
[Link]=0;
[Link]=3;
[Link](l2,gc);
[Link]=1;
[Link]=3;
[Link](b2,gc);
}
}
OUTPUT:
11
Z:\>javac [Link]
Z:\>appletviewer [Link]
[Link]: 5
12
DATE:
CARD LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”[Link]” and the
PROGRAM:
13
//program to demonstrate the card layout
import [Link].*;
import [Link].*;
add(p1);
add(p2);
}
}
OUTPUT:
14
Z:\>javac [Link]
Z:\>appletviewer [Link]
[Link]: 6
15
DATE:
AWT CONTROLS-Choice, Scrollbars
AIM: To demonstrate the Choice, Scrollbars using AWT controls in Java Applets.
ALGORITHM:
3. Create the Scrolls bars VERTICAL, HORIZONTAL by specifying in the parameters of the
Scrollbars class.
PROGRAM:
16
//To demonstrate the listbox and scrollbars AWT controls
import [Link].*;
import [Link] .*;
import [Link].*;
/*<applet code=choicelist height=500 width=500>
</applet>*/
public class choicelist extends Applet
{
Scrollbar red,blue,green;
{
Choice ch=new Choice();
[Link]("HTML");
[Link]("Oracle");
[Link]("Java");
[Link](new ch1());
add(ch);
}
public void init()
{
List l;
Color c=getBackground();
red=new Scrollbar([Link],[Link](),0,0,255);
blue=new Scrollbar([Link],[Link](),0,0,255);
green=new Scrollbar([Link],[Link](),0,0,255);
[Link](new sc());
add(red);
[Link](new sc());
add(blue);
[Link](new sc());
add(green);
l=new List();
[Link]("CSE");
[Link]("ECE");
[Link]("EEE");
add(l);
[Link](new sri());
}
class sri implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
showStatus("You have selected "+[Link]()+" in SREC");
}
}
17
public void adjustmentValueChanged(AdjustmentEvent e)
{
int r=[Link]();
int g=[Link]();
int b=[Link]();
Color c=new Color(r,g,b);
setBackground(c);
repaint();
}
}
OUTPUT:
18
Z:\>javac [Link]
Z:\>appletviewer [Link]
[Link]: 7
19
DATE:
AIM: To demonstrate the Checkbox, Option buttons using AWT controls in Java Applets.
ALGORITHM:
2. Create the Option button using the CheckboxGroup and Checkbox class.
20
PROGRAM:
import [Link].*;
import [Link] .*;
import [Link].*;
21
{
public void mouseClicked(MouseEvent e)
{
showStatus("you has selected software");
}
}
class cc1 extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
showStatus("you has selected DOS & Windows");
}
}
class cc2 extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
showStatus("you has selected MS office");
}
}
class cc3 extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
showStatus("you has selected VB");
}
}
}
22
OUTPUT:
Z:\>javac [Link]
Z:\>appletviewer [Link]
23
[Link]: 8
DATE:
COLOR PALETTE
AIM: To demonstrate the Text Formatting options of AWT controls in Java Applets
ALGORITHM:
3. Using the ActionListener event handler fire the event for the Button Control
4. Using the setForeground() and setBackground() method modify the Foreground and
Background color of the TextArea, with the object of the color class as its parameter
24
PROGRAM:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
25
if([Link]())
{
for(int i=0;i<[Link];i++)
{
if([Link]()==b[i])
[Link](color[i]);
}
}
if([Link]())
{
for(int i=0;i<[Link];i++)
{
if([Link]()==b[i])
[Link](color[i]);
}
}
}
}
26
OUTPUT:
Z:\>javac [Link]
Z:\>appletviewer [Link]
27
[Link]: 9
DATE:
URL
AIM: To write a JAVA program to Set the URL of another server, Download the homepage
ALGORITHM:
3. openConnetion() is a method in the URL class and its used to open a connection between
4. openStream() method is used to get the input stream from the web page.
5. Using FileOutputStream, we put the web page contents into a .html file
28
PROGRAM:
import [Link].*;
import [Link].*;
import [Link];
class url
{
public static void main(String args[]) throws Exception
{
int c;
URL hp=new URL("[Link]
URLConnection hpCon=[Link]();
[Link]("Date:"+new Date([Link]()));
[Link]("Content
type:"+[Link]());
[Link]("Expires:"+[Link]());
[Link]("Last-Modified:"+new Date([Link]()));
int len=[Link]();
[Link]("Content-Length:"+len);
if(len>0)
{
[Link]("====Content====");
InputStream input=[Link]();
int i=len;
while(((c=[Link]())!=-1)&&(--i>0))
{
[Link]((char-) c);
}
[Link]();
}
else
{
[Link]("No content available");
}
}
}
29
OUTPUT:
Z:\>javac [Link]
Z:\>java url
30
[Link]: 10
DATE:
CHATTING
AIM: To write a java program for implementing chatting concept by server side.
ALGORITHM:
CLIENT:
[Link] the program.
[Link] a DatagramSocket at the specified port ,for sending & receiving messages.
[Link] & initialize byte arrays to act as send & receive buffer.
[Link] DatagramPacket for sending & receiving packets using respective buffers.
ii) Send the message to client using the DatagramSocket send() method.
iii) Recieve the DatagramPacket from the client using the receive( ) method.
31
SERVER :
[Link] a DatagramSocket at the specified port ,for sending & receiving messages.
[Link] & initialize byte arrays to act as send & receive buffer.
[Link] DatagramPacket for sending & receiving packets using respective buffers.
i) Recieve the DatagramPacket from the client using the receive( ) method.
iv) Send the message to client using the DatagramSocket send() method.
32
PROGRAM:
import [Link].*;
import [Link].*;
import [Link].*;
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
33
DatagramPacket datapacket;
String s2;
datasocket=new DatagramSocket(1313);
byte []buff;
for(;;)
{
datapacket=new DatagramPacket(new byte[1024],1024);
[Link](datapacket);
String str=new String([Link]());
[Link]("Client:\n"+str);
[Link]("Server:\n");
s2=[Link]();
buff=[Link]();
datapacket=new
DatagramPacket(buff,[Link],[Link](),[Link]());
[Link](datapacket);
}
}
}
OUTPUT:
Server Client
Client: hai
Server: how are you?
Client: stop
RESULT: Thus the program for chatting has been executed successfully
34
[Link]: 11
DATE:
SERVLETS
ALGORITHM:
1. Identify the classes to be used. A class name odbc that extends from HttpServlet class
information from the browser, whenever a client browser makes a request for the HTML
page.
[Link]
35
PROGRAM:
try
{
[Link]("[Link]");
}
catch(ClassNotFoundException e)
{
[Link](e);
}
try
{
cn=[Link]("Jdbc:Odbc:ex10","","");
st=[Link]();
rs=[Link]("select * from MARKLIST where regno="+no);
[Link]("<html><title>JDBC</title>");
[Link]("<body><table cellpadding=2 cellspacing=2
border=1><th>no</th><th>name</th>");
while([Link]())
{
[Link]("<tr>");
[Link]("<td align=center>");
[Link]([Link](1));
[Link]("<td align=center>");
[Link]([Link](2));
[Link]("</td>");
}
[Link]("</table></body></html>");
36
}
catch(SQLException e2)
{
[Link](e2);
}
}
}
OUTPUT:
37
[Link]: 12
DATE: 30-08-07
TEXT FORMATTING
AIM: To demonstrate the Text Formatting options of AWT controls in Java Applets
ALGORITHM:
1. Create the TextArea,Choice Controls using the TextArea ,Choice class respectively
2. Using the ItemListener event handler fire the event for the Choice Control
3. Using the Font class modify the Font ,Font Type, Font Size.
38
PROGRAM:
//To Demonstrate the Text Formatting such as Font face, size, type
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
for(int i=0;i<3;i++)
{
[Link](fontsname[i]);
[Link](size[i]);
[Link](type[i]);
}
add(cf);
add(cs);
add(ct);
ta=new TextArea(" ",120,80);
add(ta);
}
class fontmenu implements ItemListener
{
public void itemStateChanged(ItemEvent e)
{
for(int i=0;i<[Link]; i++)
39
{
if((String)[Link]()==fontsname[i])
{
d=fontsname[i];
[Link](new Font(fontsname[i],[Link],12));
break;
}
}
}
}
40
OUTPUT:
Z:\>javac [Link]
Z:\>appletviewer [Link]
41
[Link]: 13
DATE: 06-09-07
COLLEGE INFORMATION
ALGORITHM :
42
PROGRAM:
<html>
<head>
<title>COLLEGE INFORMATION</title>
</head>
<body bgcolor=yellow>
<A NAME="HOME"></A>
<h1 align=center><u>SRI RAM ENGINEERING COLLEGE</u></h1>
<CENTER><H3>PERUMALPATTU VILLAGE,VEPPAMPATTU
R.S,<BR>THIRUVALLUR TK & Dt-602 024.<BR>(NEAR
CHENNAI)</H3></CENTER>
<h3>COURSES OFFERED
<A HREF="#CS"><H4>[Link] SCIENCE</H4></A>
<A HREF="#IT"><H4>[Link] TECHNOLOGY</H4></A>
<A HREF="#EC"><H4>[Link] AND COMMUNICATION</H4></A>
<A HREF="#EE"><H4>[Link] AND ELECTRONICS</H4></A>
<A HREF="#MECH"><H4>[Link]</H4></A>
<A HREF="#AUTO"><H4>[Link]</H4></A>
<A HREF="#CHE"><H4>[Link]</H4></A>
<br><br><br><br><br><br><br><br><br><br><br><br>
43
COMMUNICATION</u></b></h3></A><BR>
<BR>STAFF MEMBERS : 15
<BR><BR><U>STUDENTS STRENGTH</U>
<BR><BR>FIRST YEAR : 90
<BR>SECOND YEAR : 100
<BR>THIRD YEAR : 110
<BR>FOURTH YEAR : 120
<BR><BR><BR><BR>
<a href="#home"><center>CLICK HERE TO HOME</center></A>
<BR><br><br><br><br><br><br><br><br><br><br><br><br>
44
<BR>SECOND YEAR : 50
<BR>THIRD YEAR : 55
<BR>FOURTH YEAR : 60
<BR><BR><BR><BR>
<a href="#home"><Center>CLICK HERE TO HOME<Center></A>
<br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>
OUTPUT:
Z:\>[Link]
45
46
47
48
RESULT: Thus the program has been executed successfully.
49
[Link]: 14
DATE: 13-09-07
AREA LINK
AIM: To write a program in HTML to demonstrate the use of AREA LINK concept.
ALGORITHM :
50
PROGRAM:
[Link]:
<HTML>
<HEAD>
<TITLE>INFORMATION</TITLE>
</HEAD>
<BODY>
<P><map NAME="MAP">
<AREA HREF="FILE:Z:/sem7web/MAPS/[Link]" SHAPE="RECT"
COORDS="120,113,125,117">
<AREA HREF="FILE:Z:/sem7web/MAPS/[Link]" SHAPE="RECT"
COORDS="249,189,256,195">
<AREA HREF="FILE:Z:/sem7web/MAPS/[Link]" SHAPE="RECT"
COORDS="71,233,77,240">
<AREA HREF="FILE:Z:/sem7web/MAPS/[Link]" SHAPE="RECT"
COORDS="149,313,157,320">
<IMG BORDER="0" SRC="FILE:Z:/sem7web/MAPS/[Link]" USEMAP="#MAP"
WIDTH="371" HEIGHT="408"></P>
</BODY>
</HTML>
[Link]:
<HTML>
<HEAD>
<TITLE>NEW DELHI</TITLE>
</HEAD>
<BODY>
<H1>NEW DELHI</H1>
<H3><PRE>NEW DELHI IS THE CAPITAL OF INDIA
NEW DELHI
NEW DELHI
NEW DELHI
</PRE>
<A HREF="FILE:Z:/sem7web/MAPS/[Link]">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
51
[Link]:
<HTML>
<HEAD>
<TITLE>KOLKATTA</TITLE>
</HEAD>
<BODY>
<H1>KOLKATTA</H1>
<H3><PRE>KOLKATTA IS THE IMPORTANT CITY
KOLKATTA
KOLKATTA
KOLKATTA
</PRE>
<A HREF="FILE:Z:/sem7web/MAPS/[Link]">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
[Link]:
<HTML>
<HEAD>
<TITLE>CHENNAI</TITLE>
</HEAD>
<BODY>
<H1>MUMBAI</H1>
<H3><PRE>MUMBAI IS THE IMPORTANT CITY
MUMBAI
MUMBAI
MUMBAI
</PRE>
<A HREF="FILE:Z:/sem7web/MAPS/[Link]" link="blue" alink="red"
vlink="cyan">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
52
[Link]:
<HTML>
<HEAD>
<TITLE>CHENNAI</TITLE>
</HEAD>
<BODY>
<H1>CHENNAI</H1>
<H3><PRE>CHENNAI IS THE IMPORTANT CITY
CHENNAI
CHENNAI
CHENNAI
</PRE>
<A HREF="FILE:Z:/sem7web/MAPS/[Link]">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
53
OUTPUT:
54
55
RESULT: Thus the program has been executed successfully.
56
[Link]: 15
DATE:
AIM: To create a webpage using Casecading stylesheet embedded and inline style sheet.
ALGORITHM:
2. For an Embedded style sheet the text is formatted by importing the format specified in
style tag.
3. For an linked style sheet the text is formatted by importing the format specified in different
file.
4. For an Inline style sheet the text is formatted by using the style specified in each and every
tag.
57
PROGRAM:
EMBEDDED
<html>
<head>
<title>stylesheet</title>
</head>
<style>
body
{
background:white;
margin-left:1 in;
margin-right:1.5in;
}
H1
{
font-size:16pt;
color:green;
font-family:verdana;
text-align:center;
}
</style>
</head>
<body>
<p>Hi!Hello<br>SRI RAM Engg [Link] college has a good infrastructure and campus
</p>
<h1>THIS IS H1</h1>
</body>
</html>
EXTERNAL
<html>
<head>
<link rel="stylesheet" href="[Link]" type="text/css"></link>
</head>
<body>
Hi there!<p><br>SRI RAM college has seperate labs for each department and all labs are
available to the students till 8.30 [Link] college also encourages the students to excel in extra
curicular activities and other cultural activities.
</p>
</body>
</html>
[Link]
Body
{
font-size:12pt;
58
font-family:arial;
color:brown;
background:white;
}
p
{
font-size:10pt;
font-family:verdana;
color:blue;
text-indent:0.5in;
margin-left:50px;
margin-right:50px;
}
INLINE
<html>
<head>
<style>
.tech
{
font-weight:bold;
color:blue;
}
</style>
</head>
<body>
<p class ="tech">Hi this is class style sheet<br> This is SRI RAM engineering college
</p>
</body>
</html>
59
OUTPUT:
EMBEDDED OUTPUT:
Hi!Hello
SRI RAM Engg [Link] college has a good infrastructure and campus
THIS IS H1
EXTERNAL OUTPUT:
Hi there!
SRI RAM college has seperate labs for each department and all labs are
available to the students till 8.30 [Link] college also encourages the
students to excel in extra curicular activities and other cultural activities.
INLINE OUTPUT:
60