Internet Programming
Internet Programming
NO: 1
DATE:
FLOW LAYOUT
ALGORITHM:
1
PROGRAM:
import java.awt.*;
import java.applet.*;
2
OUTPUT:
Z:\>javac flowlayout.java
Z:\>appletviewer flowlayout.java
3
EX.NO: 2
DATE:
BORDER LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”classname.class” and the
4
PROGRAM:
import java.applet.*;
import java.awt.*;
5
OUTPUT:
Z:\>javac borderlayout.java
Z:\>appletviewer borderlayout.java
6
EX.NO: 3
DATE:
GRID LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”classname.class” and the
PROGRAM:
7
//program to demonstrate the grid layout
import java.applet.*;
import java.awt.*;
for(int i=0;i<12;i++)
{
add(new Button(""+i));
}
}
}
8
OUTPUT:
Z:\>javac gridlayout.java
Z:\>appletviewer gridlayout.java
EX.NO: 4
9
DATE:
GRIDBAG LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”classname.class” and the
PROGRAM:
10
// program to demonstrate the gridbag layout
import java.awt.*;
import java.applet.*;
/*<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");
gc.fill=GridBagConstraints.BOTH;
gb.setConstraints(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);
gc.gridx=0;
gc.gridy=2;
gb.setConstraints(l1,gc);
gc.gridx=1;
gc.gridy=2;
gb.setConstraints(b1,gc);
gc.gridx=0;
gc.gridy=3;
gb.setConstraints(l2,gc);
gc.gridx=1;
gc.gridy=3;
gb.setConstraints(b2,gc);
}
}
OUTPUT:
11
Z:\>javac gridbag.java
Z:\>appletviewer gridbag.java
EX.NO: 5
12
DATE:
CARD LAYOUT
ALGORITHM:
3. Include the comment statement <applet> which contains code=”classname.class” and the
PROGRAM:
13
//program to demonstrate the card layout
import java.awt.*;
import java.applet.*;
add(p1);
add(p2);
}
}
OUTPUT:
14
Z:\>javac cardlayout.java
Z:\>appletviewer cardlayout.java
EX.NO: 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 java.awt.*;
import java.awt.event .*;
import java.applet.*;
/*<applet code=choicelist height=500 width=500>
</applet>*/
public class choicelist extends Applet
{
Scrollbar red,blue,green;
{
Choice ch=new Choice();
ch.addItem("HTML");
ch.addItem("Oracle");
ch.addItem("Java");
ch.addItemListener(new ch1());
add(ch);
}
public void init()
{
List l;
Color c=getBackground();
red=new Scrollbar(Scrollbar.HORIZONTAL,c.getRed(),0,0,255);
blue=new Scrollbar(Scrollbar.HORIZONTAL,c.getBlue(),0,0,255);
green=new Scrollbar(Scrollbar.VERTICAL,c.getGreen(),0,0,255);
red.addAdjustmentListener(new sc());
add(red);
blue.addAdjustmentListener(new sc());
add(blue);
green.addAdjustmentListener(new sc());
add(green);
l=new List();
l.add("CSE");
l.add("ECE");
l.add("EEE");
add(l);
l.addActionListener(new sri());
}
class sri implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
showStatus("You have selected "+e.getActionCommand()+" in SREC");
}
}
17
public void adjustmentValueChanged(AdjustmentEvent e)
{
int r=red.getValue();
int g=green.getValue();
int b=blue.getValue();
Color c=new Color(r,g,b);
setBackground(c);
repaint();
}
}
OUTPUT:
18
Z:\>javac choicelist.java
Z:\>appletviewer choicelist.java
EX.NO: 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 java.awt.*;
import java.awt.event .*;
import java.applet.*;
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 checkbox.java
Z:\>appletviewer checkbox.java
23
EX.NO: 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 java.io.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
25
if(cb.getState())
{
for(int i=0;i<color.length;i++)
{
if(e.getSource()==b[i])
a.setBackground(color[i]);
}
}
if(cf.getState())
{
for(int i=0;i<color.length;i++)
{
if(e.getSource()==b[i])
a.setForeground(color[i]);
}
}
}
}
26
OUTPUT:
Z:\>javac palette.java
Z:\>appletviewer palette.java
27
EX.NO: 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 java.net.*;
import java.io.*;
import java.util.Date;
class url
{
public static void main(String args[]) throws Exception
{
int c;
URL hp=new URL("http://www.google.com");
URLConnection hpCon=hp.openConnection();
System.out.println("Date:"+new Date(hpCon.getDate()));
System.out.println("Content
type:"+hpCon.getContentType());
System.out.println("Expires:"+hpCon.getContentType());
System.out.println("Last-Modified:"+new Date(hpCon.getLastModified()));
int len=hpCon.getContentLength();
System.out.println("Content-Length:"+len);
if(len>0)
{
System.out.println("====Content====");
InputStream input=hpCon.getInputStream();
int i=len;
while(((c=input.read())!=-1)&&(--i>0))
{
System.out.println((char-) c);
}
input.close();
}
else
{
System.out.println("No content available");
}
}
}
29
OUTPUT:
Z:\>javac url.java
Z:\>java url
30
EX.NO: 10
DATE:
CHATTING
AIM: To write a java program for implementing chatting concept by server side.
ALGORITHM:
CLIENT:
1.Start the program.
4.Create a DatagramSocket at the specified port ,for sending & receiving messages.
5.Declare & initialize byte arrays to act as send & receive buffer.
7.Create 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 :
4.Create a DatagramSocket at the specified port ,for sending & receiving messages.
5.Declare & initialize byte arrays to act as send & receive buffer.
7.Create 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 java.net.*;
import java.io.*;
import java.util.*;
}
}
}
import java.net.*;
import java.io.*;
import java.util.*;
33
DatagramPacket datapacket;
String s2;
datasocket=new DatagramSocket(1313);
byte []buff;
for(;;)
{
datapacket=new DatagramPacket(new byte[1024],1024);
datasocket.receive(datapacket);
String str=new String(datapacket.getData());
System.out.println("Client:\n"+str);
System.out.println("Server:\n");
s2=d.readLine();
buff=s2.getBytes();
datapacket=new
DatagramPacket(buff,buff.length,datapacket.getAddress(),datapacket.getPort());
datasocket.send(datapacket);
}
}
}
OUTPUT:
Server Client
Client: hai
Server: how are you?
Client: stop
RESULT: Thus the program for chatting has been executed successfully
34
EX.NO: 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.
http://127.0.0.1:8080/java/odbc
35
PROGRAM:
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
try
{
cn=DriverManager.getConnection("Jdbc:Odbc:ex10","","");
st=cn.createStatement();
rs=st.executeQuery("select * from MARKLIST where regno="+no);
pw.println("<html><title>JDBC</title>");
pw.println("<body><table cellpadding=2 cellspacing=2
border=1><th>no</th><th>name</th>");
while(rs.next())
{
pw.println("<tr>");
pw.println("<td align=center>");
pw.println(rs.getInt(1));
pw.println("<td align=center>");
pw.println(rs.getString(2));
pw.println("</td>");
}
pw.println("</table></body></html>");
36
}
catch(SQLException e2)
{
System.out.println(e2);
}
}
}
OUTPUT:
37
EX.NO: 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 java.io.*;
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.awt.event.*;
for(int i=0;i<3;i++)
{
cf.addItem(fontsname[i]);
cs.addItem(size[i]);
ct.addItem(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<fontsname.length; i++)
39
{
if((String)e.getItem()==fontsname[i])
{
d=fontsname[i];
ta.setFont(new Font(fontsname[i],Font.PLAIN,12));
break;
}
}
}
}
40
OUTPUT:
Z:\>javac textformat.java
Z:\>appletviewer textformat.java
41
EX.NO: 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>1.COMPUTER SCIENCE</H4></A>
<A HREF="#IT"><H4>2.INFORMATION TECHNOLOGY</H4></A>
<A HREF="#EC"><H4>3.ELECTRONICS AND COMMUNICATION</H4></A>
<A HREF="#EE"><H4>4.ELECTRICAL AND ELECTRONICS</H4></A>
<A HREF="#MECH"><H4>5.MECHANICAL</H4></A>
<A HREF="#AUTO"><H4>6.AUTOMOBILE</H4></A>
<A HREF="#CHE"><H4>7.CHEMICAL</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:\>college.html
45
46
47
48
RESULT: Thus the program has been executed successfully.
49
EX.NO: 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:
INDIA.HTML:
<HTML>
<HEAD>
<TITLE>INFORMATION</TITLE>
</HEAD>
<BODY>
<P><map NAME="MAP">
<AREA HREF="FILE:Z:/sem7web/MAPS/DELHI.HTML" SHAPE="RECT"
COORDS="120,113,125,117">
<AREA HREF="FILE:Z:/sem7web/MAPS/KOLKATTA.HTML" SHAPE="RECT"
COORDS="249,189,256,195">
<AREA HREF="FILE:Z:/sem7web/MAPS/MUMBAI.HTML" SHAPE="RECT"
COORDS="71,233,77,240">
<AREA HREF="FILE:Z:/sem7web/MAPS/CHENNAI.HTML" SHAPE="RECT"
COORDS="149,313,157,320">
<IMG BORDER="0" SRC="FILE:Z:/sem7web/MAPS/MAP4.BMP" USEMAP="#MAP"
WIDTH="371" HEIGHT="408"></P>
</BODY>
</HTML>
DELHI.HTML:
<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/INDIA.HTML">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
51
KOLKATTA.HTML:
<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/INDIA.HTML">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
MUMBAI.HTML:
<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/INDIA.HTML" link="blue" alink="red"
vlink="cyan">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
52
CHENNAI.HTML:
<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/INDIA.HTML">CLICK HERE TO HOME PAGE
</H3>
</BODY>
</HTML>
53
OUTPUT:
54
55
RESULT: Thus the program has been executed successfully.
56
EX.NO: 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 College.The college has a good infrastructure and campus
</p>
<h1>THIS IS H1</h1>
</body>
</html>
EXTERNAL
<html>
<head>
<link rel="stylesheet" href="mystyle.css" 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 pm.the college also encourages the students to excel in extra
curicular activities and other cultural activities.
</p>
</body>
</html>
MYSTYLE.CSS
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 College.The 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 pm.the college also encourages the
students to excel in extra curicular activities and other cultural activities.
INLINE OUTPUT:
60