Uploaded by telugu techworld

IP Lab Manual FINAL

advertisement
INETERNET PROGRAMMING LAB
EXP.NO:1.a
DATE :
HTML TAGS
BASIC HTML TAGS
Aim: To create a simple html file to demonstrate the use of different tags.
PROCEDURE
STEP 1:
Open Net beans IDE.
STEP 2:
Select File->New File->others->HTML file.
STEP 3:
Give a File name and location where the file should be saved.
STEP 4:
And then, Click Finish.
STEP 5:
By using above steps, open HTML file for another four files.
PROBLEM STATEMENT :
Create an html page named as “: Basic_Html_Tags.html”
Add the following tags detail.
1. Set the title of the page as “Basic Html Tags”
2. Within the body perform the following
a) Moving text = “Basic HTML Tags”
b) Different heading tags ( h1 to h6)
c) Paragraph
d) Horizontal line
e) Line Break
f) Link
g) HTML Formatting (<b>, <u>, <sub>, <sup>….)
h) orderedand unordered list and nested list
PROGRAM :
<html>
<head>
<title> Basic Html Tags</title>
</head>
<body>
<marquee > Basic HTML Tags</marquee>
<h1 > Heading H1 </h1>
<h2 > Heading H2 </h2>
<h3 > Heading H3 </h3>
<h4> Heading H4 </h4>
<h5> Heading H5 </h5>
<h6> Heading H6 </h6>
<hr>
<h4><center>Paragraph Tags</center></h4>
<p>
<h4> About VELS UNVERSITY</h4>
VAEL’S EDUCATIONAL TRUSTwas established in 1992 with the aim of transforming an
individual into a complete man with character and ability committed to national service
and development. The trust was founded by Dr. Ishari K Ganesh, M.Com, MBA, B.L, (M.L),
Ph.D, a visionary and an eminent educationist, in fond memory of his father Shri.Isari Velan,
a former minister in the popular Govt. of Dr. MGR. Vael’s Educational Trust has always
served to take education to the thresholds of first generation learners and weaker sections
of the society.
</p>
<hr>
<h4><center>Line break Tags</center></h4>
This is a long piece of text consisting of three<BR>
sentences and shows you the functions of the<BR>
Line Break tag. This tag is used quite frequently<BR>
to add line breaks in the HTML code. It is also used<BR>
to add blank lines to a document.<BR>
<HR>
<h4><center> HTML fORMATTING </center>
<p> This is <i> italized </i></p>
<p> This is <u> underlined </u></p>
<p> This is <b> bold </b></p>
<p> This is <em> emphasized </em></p>
<p>This is <Strong> Strong Text </strong></p>
<p> This is <s> striked text </s></p>
<p> This is <code> computer code </code></p>
<p> This is <sup> superscript </sup> code </p>
<p> This is <sub> subscript </sub> code </p>
<p> This is <big> big text </big></p>
<p> This is <small> small text </small></p>
<center><FONT COLOR="#0000FF"> Listing Tags</FONT></center>
<h4>Numbered list:</h4>
<ol>
<li>java</li>
<li>perl</li>
<li>c++</li>
</ol>
<h4>Letters list:</h4>
<ol type="A">
<li>smtp</li>
<li>http</li>
<li>ftp</li>
</ol>
<h4>Lowercase letters list:</h4>
<ol type="a" start="2">
<li>php</li>
<li>javascript</li>
<li>ajax</li>
</ol>
<h4>Roman numbers list:</h4>
<ol type="I">
<li>DTE</li>
<li>JCTE</li>
<li>SITTTR</li>
</ol>
<h4>Lowercase Roman numbers list:</h4>
<ol type="i" start="4" >
<li>Computer Engg.</li>
<li>Mechanical Engg.</li>
<li>Electronics Engg.</li>
</ol>
<h3>Here is a nested ordered list:</h3>
<ol type="I">
<li>Module 1</li>
<li>Module 2
<ol type="i">
<li>Module 2.1</li>
<li>Module 2.2</li>
</ol>
</li>
<li>Module 3</li>
</ol>
<h4>Disc bullets list:</h4>
<ul type="disc">
<li>Keyboard</li>
<li>Mouse</li>
<li>Moniter</li>
</ul>
<h4>Circle bullets list:</h4>
<ul type="circle">
<li>CRT</li>
<li>LCD</li>
<li>LED</li>
</ul>
<h4>Square bullets list:</h4>
<ul type="square">
<li>Windows</li>
<li>Linux</li>
<li>Android</li>
</ul>
<h4>A Definition List:</h4>
<dl>
<dt>Coffee</dt>
<dd>Black Coffee OR Milk Coffee</dd>
<dt>Milk</dt>
<dd>Hot White milk OR Cold Chocolate Milk</dd>
</dl>
<hr>
</body>
</html>
OUTPUT
EXP.NO:1.b
DATE:
HTML TAGS
Frames ,Tables ,Style & Multimedia
Aim:- To create an html file to link to different html page which contains images,
tables,Video and and style attribute
PROCEDURE
STEP 1:
Open Net beans IDE.
STEP 2:
Select File->New File->others->HTML file.
STEP 3:
Give a File name and location where the file should be saved.
STEP 4:
And then, Click Finish.
STEP 5:
By using above steps, open HTML file for another four files.
Problem Statement :
1. Create an html page named as “Table.html” to display any data. Provide various color
options to the cells
2. Create an html page named as “image.html” to display image.
3. Create an html page named as “video.html” to display the audio and video files.
4) Create an html page named as “style.html” to display a paragaraph page with style
attribute
With back ground color
Heading center aligned
Paragraph with font courier and size 100 and color red
5) Create a frame and call all the HTML.
PROGRAM:
<HTML>
<FRAMESET COLS="50%, 50%" ROWS= "50%, 50%">
<FRAME SRC="style.html">
<FRAME SRC="table.html">
<FRAME SRC="image.html">
<FRAME SRC=" video.html">
</FRAMESET>
</HTML>
style.html
<html>
<body style = "background-color:blue">
<h1 style = "text-align : center" ; color : green > About Vels University </h1>
<p style=" font-family:courier ; font-size :12; color : red " >
VAEL’S EDUCATIONAL TRUSTwas established in 1992 with the aim of transforming an
individual into a complete man with character and ability committed to national service
and development. The trust was founded by Dr. Ishari K Ganesh, M.Com, MBA, B.L, (M.L),
Ph.D, a visionary and an eminent educationist, in fond memory of his father Shri.Isari Velan,
a former minister in the popular Govt. of Dr. MGR. Vael’s Educational Trust has always
served to take education to the thresholds of first generation learners and weaker sections
of the society.
</p1>
</body>
</html>
table.html
<html>
<body>
<table border=1 cellspacing=20pt>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
</body>
</html>
image.html
<html>
<body>
<img src="vels.png" >
</body>
</html>
video.html
<html>
<body>
<a href="Wildlife.wmv">Click here to Play a video file </a>
<HR>
<video width="320" height="240" controls="controls">
<source src=" C:\Users\Public\Videos\ Wildlife.wmv " type="video/wmv">
Your browser does not support the video tag.
/>
</video>
</body>
</html>
OUTPUT
EXP.NO:2
DATE:
WEB PAGE CREATION
Registration Form with form elements
Aim: To create a registration form using form elements
PROCEDURE
STEP 1:
Open Net beans IDE.
STEP 2:
Select File->New File->others->HTML file.
STEP 3:
Give a File name and location where the file should be saved.
STEP 4:
And then, Click Finish.
Problem Statement :
Create an html page named as “registration.html”
1. Set background colors
2. Use table for alignment
3. Provide font colors & size
4.Create form fields for :Name,Age,address,Sex,Nationality,Languages
known,Password,submit button and reset button.
5.Choose appropriate textbox,listbox,textarea for form fields
PROGRAM
<html>
<head>
<title>Registration Form Sample</title>
</head>
<body bgcolor="lightblue" text="red" style="font-size:15pt;font-family:arial" ><center>
<h2>ENTRY FORM</h3></center>
<form >
<table cellspacing=15pt>
<tr>
<td align=left> Enter your Name :</td>
<td align=left><input type=text name=t1 size=18></td>
</tr>
<tr>
<td align=left>Enter your Age : </td>
<td align=left><input type=text name=t2 maxlength=3 size=3></td>
<tr>
<td align=left>Enter your Address :</td>
<td align=left><textarea name=ta rows=5 cols=15></textarea></td>
</tr>
<tr>
<td align=left>Sex : </td>
<td align=left><input type=radio name=r1 value="female" checked=true>Female<br>
<input type=radio name=r1 value=male>Male</td>
</tr>
<tr>
<td align=left>Nationality : </td>
<td align=left>
<select name="country">
<option selected="" value="Default">(Please select a country)</option>
<option value="AF">India</option>
<option value="AL">Canada</option>
<option value="DZ">Australia</option>
<option value="AS">Russia</option>
<option value="AD">USA</option>
</select>
</td>
</tr>
<tr>
<td align=left> Languages Known :</td>
<td align=left><center>(can select more than one)</center>
<input type=checkbox name=c1 value=c checked=true> C<br>
<input type=checkbox name=c2 value=c++> C++<br>
<input type=checkbox name=c3 value=vb> VB<br>
<input type=checkbox name=c4 value=java> JAVA<br>
<input type=checkbox name=c5 value=asp> ASP<br>
<input type=checkbox name=c6 value=others> OTHERS<br></td>
</tr>
<tr>
<td align=left>Enter your Password : </td>
<td align=right><input type=password name=t3 size=18>
</tr>
</table>
<center>
<input type=reset value=" Reset " >
<input type=submit value=" Submit " >
</center>
</form>
</body>
</html>
OUTPUT
EXP.NO:3
DATE:
WEB PAGE CREATION
REGISTRATION FORM USING AWT
Aim:
To write a java Registration form program using the java AWT java components
PROCEDURE
STEP 1:Open Net beans IDE.
STEP 2: Click File -> New -> Project
STEP 3: CHOOSE JAVA->JAVA APPLICATION
STEP 4: Give Project Name any name relevant to the Program
STEP 5:Click Finish
Problem Statement :
•
•
•
•
Create a java AWT Java Student Registration program with
nane,age,Sex(M/F),Address,Course,Semester and Save button
Create a frame and us e appropriate radiobutton ,checkbox ,List ,Choice item for
each Field
Set the Field Size and color
Set background color
PROGRAM
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
{
public class studentregistrationmodified implements ActionListener
String msg;
Button b1=new Button("save");
Label l11=new Label("Student details",Label.CENTER);
Label l1=new Label("Name:",Label.LEFT);
Label l2=new Label("age:",Label.LEFT);
Label l3=new Label("Sex(M/F):",Label.LEFT);
Label l4=new Label("Address:",Label.LEFT);
Label l5=new Label("Course:",Label.LEFT);
Label l6=new Label("Semester:",Label.LEFT);
Label l7=new Label("",Label.RIGHT);
TextField t1=new TextField();
Choice c1=new Choice();
CheckboxGroup cbg=new CheckboxGroup();
Checkbox ck1=new Checkbox("Male",false,cbg);
Checkbox ck2=new Checkbox("Female",false,cbg);
TextArea t2=new TextArea("",180,90,TextArea.SCROLLBARS_VERTICAL_ONLY);
Choice course=new Choice();
Choice sem=new Choice();
Choice age=new Choice();
Frame frame;
public static void main(String g[])
{
studentregistrationmodified stu;
stu = new studentregistrationmodified ();
}
public studentregistrationmodified()
{
Frame f;
f = new Frame();
f.setSize(500,500);
f.setTitle("student registration");
f.setVisible(true);
f.setBackground(Color.cyan);
f.setForeground(Color.black);
f.setLayout(null);
f.add(l11);
f.add(l1);
f.add(l2);
f.add(l3);
f.add(l4);
f.add(l5);
f.add(l6);
f.add(l7);
f.add(t1);
f.add(t2);
f.add(ck1);
f.add(ck2);
f.add(course);
f.add(sem);
f.add(age);
f.add(b1);
b1.addActionListener(this);
f.add(b1);
course.add("BSc c.s");
course.add("BSc maths");
course.add("BSc physics");
course.add("BA English");
course.add("BCOM");
sem.add("1");
sem.add("2");
sem.add("3");
sem.add("4");
sem.add("5");
sem.add("6");
age.add("17");
age.add("18");
age.add("19");
age.add("20");
age.add("21");
l1.setBounds(25,65,90,20);
l2.setBounds(25,90,90,20);
l3.setBounds(25,120,90,20);
l4.setBounds(25,185,90,20);
l5.setBounds(25,260,90,20);
l6.setBounds(25,290,90,20);
l7.setBounds(25,260,90,20);
l11.setBounds(10,40,280,20);
t1.setBounds(120,65,170,20);
t2.setBounds(120,185,170,60);
ck1.setBounds(120,120,50,20);
ck2.setBounds(170,120,60,20);
course.setBounds(120,260,100,20);
sem.setBounds(120,290,50,20);
age.setBounds(120,90,50,20);
b1.setBounds(120,350,50,30);
);
}
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("save"))
{
System.out.println("Student details saved!");
}
}
}
OUTPUT
EXP.NO:4A
DATE:
CLIENT SIDE SCRIPTS FOR VALIDATING WEB FORM CONTROLS USING DHTML
Registration form with Validation
Aim: To create a HTML program for Registration Form and validation with Java Script.
PROCEDURE
STEP 1:
Open Net beans IDE.
STEP 2:
Select File->New File->others->HTML file.
STEP 3:
Give a File name and location where the file should be saved.
STEP 4:
And then, Click Finish.
PROBLEM STATEMENT:
Create an html page named as “validate_registration.html”
1. Define a method name as “reset()” to be called when reset button is clicked and manually
set all
values of fields to default.
2. Define a method name as “check()” to be called when check button is clicked.
a) Here check for blank entry, name, age, email, phone no, radio button, checkbox.
b) Once all the valuables are properly filled make the submit button to be visible.
3. Define the various fields using textbox,checkbox,radiobutton,submit button ,reset button
in form using table.
6.Check age should be greater than 20 and less than 35.
PROGRAM
<html>
<head>
<script >
function reset1()
{
x=confirm("It will clear all the text entered")
if(x==true)
{
document.form1.t0.value=""
document.form1.t1.value=""
document.form1.t2.value=""
document.form1.ta.value=""
document.form1.t3.value=""
document.form1.t4.value=""
document.form1.country.value=""
document.form1.r1[0].checked=false
document.form1.r1[1].checked=false
document.form1.c1.checked=false
document.form1.c2.checked=false
document.form1.c3.checked=false
document.form1.c4.checked=false
document.form1.t1.focus()
}
}
function check()
{
var ee=document.form1.t0.value;
var atpos=ee.indexOf("@");
var dotpos=ee.lastIndexOf(".");
if(atpos<1||dotpos<atpos+2||dotpos+2>=ee.length)
{
alert("please enter a valid email id")
document.form1.t0.value=""
document.form1.t0.focus()
}
else if((document.form1.t1.value=="")||(!(isNaN(document.form1.t1.value))))
{
alert("please enter the correct name")
document.form1.t1.value=""
document.form1.t1.focus()
}
else if((document.form1.t2.value=="")||(isNaN(document.form1.t2.value)))
{
alert("please enter the age correctly")
document.form1.t2.value=""
document.form1.t2.focus()
}
else if((document.form1.t2.value>40)||(document.form1.t2.value<18))
{
alert("Sorry you age is beyound the limits")
document.form1.t2.value=""
document.form1.t2.focus()
}
else if(document.form1.ta.value=="")
{
alert("please enter the address")
document.form1.ta.focus()
}
else if((document.form1.r1[0].checked==false)&&(document.form1.r1[1].checked==false))
{
alert("please select Male or Female")
document.form1.r1[0].focus()
}
else if((document.form1.country.value==""))
{
alert("please select a country")
document.form1.country.focus()
}
else if((document.form1.c1.checked==false)&&(document.form1.c2.checked==false)&&
(document.form1.c3.checked==false))
{
alert("please select the the languages known")
document.form1.c1.focus()
}
else if(document.form1.t3.value=="")
{
alert("please enter the password")
document.form1.t3.focus()
}
else if(document.form1.t4.value=="")
{
alert("please Re-Enter the password")
document.form1.t4.focus()
}
else if(document.form1.t4.value!=document.form1.t3.value)
{
alert(" passwrd mismatch please enter the password")
document.form1.t3.focus()
}
else if(
&
(document.form1.t0.value!="")&&
(document.form1.t1.value!="")&&
(document.form1.t2.value!="")&&
(document.form1.t3.value!="")&&
(document.form1.t4.value!="")&&
(document.form1.ta.value!="")&&
((document.form1.r1[0].checked!=false)||(document.form1.r1[0].checked!=false))&
((document.form1.c1.checked!=false)||(document.form1.c2.checked!=false)||(docu
ment.form1.c3.checked!=false)||
(document.form1.c4.checked!=false)||(document.form1.c5.checked!=false))
)
{
x=confirm("you have entered the datas correctly,want to submit the form")
if(x)
{
document.lay.visibility="show"
}
}
return false;
}
</script>
</head>
<body bgcolor="lightblue" text="red" style="font-size:10pt;font-family:Garamond"
onload=document.form1.t0.focus() >
<center>
<h2>ENTRY FORM</h2></center>
<form name=form1 >
<table >
<tr><td align=left><h2>Enter your email id :</h2></td><td align=right><input type=text
name=t0
size=18>
<tr><td align=left><h2>Enter your Name :</h2></td><td align=right><input type=text
name=t1
size=18>
<tr><td align=left><h2>Enter your Age :</h2></td><td align=right><input type=text
name=t2
maxlength=3 size=4>
<tr><td align=left><h2>Enter your Address :</h2></td><td align=right><textarea
name=ta rows=4
cols=15></textarea>
<tr><td align=left><h2>Sex :</h2></td><td align=left><input type=radio name=r1
value="female">Female<br>
<input type=radio name=r1 value=male>Male</td>
<tr><td align=left><h2>Nationality :</h2></td><td align=left><select name="country">
<option selected="" value="">(Please select a country)</option>
<option value="AF">India</option>
<option value="AL">Canada</option>
<option value="DZ">Australia</option>
<option value="AS">Russia</option>
<option value="AD">USA</option>
</select></td>
<tr><td align=left><h2>Languages Known :</h2></td><td align=left><center>(select
more than
one)</center>
<input type=checkbox name=c1 value=c>C
<input type=checkbox name=c2 value=c++>C++
<input type=checkbox name=c3 value=java>JAVA
</td>
<tr><td align=left><h2>Enter your Password :</h2></td><td align=right><input
type=password
name=t3 size=18>
<tr><td align=left><h2>Re-type Password :</h2></td><td align=right><input
type=password
name=t4 size=18>
</table>
<center>
<input type="button" onclick="check()" value="submit" />
<input type="button" onclick="reset1()" value="reset" />
</center>
</form>
</body>
</html>
OUTPUT
EXP.NO:4.B
DATE:
CLIENT SIDE SCRIPTS FOR VALIDATING WEB FORM CONTROLS
Online Exam Form with Validation
Aim: To create a html page to show online exam using JavaScript.
PROCEDURE
STEP 1:
Open Net beans IDE.
STEP 2:
Select File->New File->others->HTML file.
STEP 3:
Give a File name and location where the file should be saved.
STEP 4:
And then, Click Finish.
Problem Statement:
1. Create an html file named as exam.html
a. Display four Questions and have four optional answers using radio buttons.
b. Display the result in a alert box.
c. Reset the page into initial condition for next exam.
PROGRAM
<html>
<head>
<title>Exam</title>
<script language="javascript">
function exam(form)
{
var i=0;
if(form.one[2].checked)
i=i+1;
if(form.three[0].checked)
i=i+1;
if(form.four[0].checked)
i=i+1;
if(form.five[1].checked)
i=i+1;
window.alert("Thank You Taking Online Exam! Your Score is: "+i);
}
</script>
</head>
<body bgcolor=silver>
<form onSubmit="exam(this)">
<center><h1><blink>WELCOME TO ONLINE EXAM FORM</blink></h1></center>
<p>
<h1>1)Which is platform independent language</h1>
<input type="radio" name="one" value="c++">
<label>c++</label>
<input type="radio" name="one" value="c">
<label>c</label>
<input type="radio" name="one" value="java">
<label>java</label>
<input type="radio" name="one"value="basic">
<label>BASIC</label>
</p>
<p>
<h1>2) Which is class of all class in java</h1>
<input type="radio" name="three" value="object">
<label>Object</label>
<input type="radio" name="three" value="math">
<label>Math</label>
<input type="radio" name="three" value="system">
<label>System</label>
<input type="radio" name="three" value="graphic">
<label>Graphic</label></p>
<p>
<h1>3)Frame package is in which package</h1>
<input type="radio" name="four" value="awt">
<label>AWT</label>
<input type="radio" name="four" value="applet">
<label>Applet</label>
<input type="radio" name="four" value="lang">
<label>Lang</label>
<input type="radio" name="four" value="swing">
<label>Swing</label>
</p>
<p>
<h1>4)Java does not support</h1>
<input type="radio" name="five" value="inheritance">
<label>Inheritance</label>
<input type="radio" name="five" value="multiple inheritance">
<label>Multilple inheritance</label>
<input type="radio" name="five" value="polymorphism">
<label>Polymorphism</label>
<input type="radio" name="five" value="encryption">
<label>Encryption</label>
</p>
<p><center>
<input type="submit" value="Submit">
<input type ="reset" value="Reset">
</center></p>
</body>
</html>
OUTPUT
EXP.NO:5
DATE:
CASCADING STYLE SHEET
Web page with all types of Cascading style sheets.
Aim :To create web pages using college information to demonstrate the style sheets
PROCEDURE
STEP 1:
Open Net beans IDE.
STEP 2:
Select File->New File->others->HTML file.
STEP 3:
Give a File name and location where the file should be saved.
STEP 4:
And then, Click Finish.
STEP 5:
Select File->New File->others->CSS file to create a CSS File.
Problem Statement:
1.Create a external style sheet named as “external_css.css” and provide some styles for h2,
hr, and link tag
2. Create an html file with paragraph and headings ,image and link
3. Include the external style sheet with necessary tag.
4. Include the internal style sheet for body tags & also use class name, so that the style can
beapplied for all tags.
PROGRAM
MAIN.HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="external_style.css" />
<style type="text/css">
body
{
margin-left:100px;
background:silver url('vels.png') no-repeat top left;
}
.container
{
text-align:center;
}
.center_div
{
border:1px solid gray;
margin-left:auto;
margin-right:auto;
width:90%;
background-color:#d0f0f6;
text-align:left;
padding:8px;
}
.para1
{
border-style:dotted solid dashed double;
color:blue;
}
.para2
{
border-style:dotted solid dashed;
color:green
}
.para3
{
border-style:dotted solid;
color:red;
}
.para4
{
border-style:dotted;
color:Magenta
}
</style>
</head>
<body>
<div class="container">
<div class="center_div">
<h1>Hai !</h1>
<p>
<h2> Vael’s Educational Trust</h2>
was established in 1992 with the aim of transforming an individual into a complete man
with character and ability committed to national service and development. The trust was
founded by Dr. Ishari K Ganesh, M.Com, MBA, B.L, (M.L), Ph.D, a visionary and an eminent
educationist, in fond memory of his father Shri.Isari Velan, a former minister in the popular
Govt. of Dr. MGR. Vael’s Educational Trust has always served to take education to the
thresholds of first generation learners and weaker sections of the society.
</p>
</div>
</div>
<p class=para1>
<h2>Computer Science and Engineering</h2>
The Department of Computer Science and Engineering is established in the year 2008 and
committed to provide students with a platform for gaining knowledge covering the depth
and breadth of the specialization as well as equipping them with the skills required to
mould them into successful professionals. The Courses offered in the Department meet the
requirements of both industry and research. The Department is well equipped with
excellent computing facilities, latest software and state-of-the-art IT infrastructure. The
Department has well experienced and dedicated faculty members with different
specializations. Recently revised curriculum has reduced course load and greater emphasis
on design and project work. It emphasizes the need for independent thinking and
encourages students to get involved in interesting and innovative projects. Organizing
seminars/workshops etc. is a regular feature of the Department. Students are encouraged
to participate in extra-curricular activities and competitions conducted by other
universities and colleges in and around the state. The students have won laurels to the
college by winning prizes in competitions.</p>
<p class= para2>
<h2> Electronics and Communication Engineering</h2>
The Department of Electronics and Communication Engineering has excellent
infrastructure in terms of laboratories, classrooms, seminar halls etc. The Department has
excellent teaching faculty who are a blend of knowledge and experience. The curriculum
consists of both basics and advanced topics of ECE with strong mathematical and computer
foundations. </p>
<p class=para3>
<h2>Mechanical Engineering</h2>
The Department of Mechanical Engineering is equipped with the best of resources to enrich
the ancestry of the department ensuring high quality education to the students. The intense
professional will of the faculty is the root for the sustained excellence of the department.
The state-of-the-art laboratories, the well-balanced curriculum and the faculty with ironresolve, address the cognitive capacities as well as practical hands on workshop experience
of students in fulfilling the ever more pressing needs of the industry.</p>
<p class=para4>
<h2>Civil Engineering</h2>
Civil Engineering has a special status in engineering education. Civil Engineering plays a
key role in the development of any field of Engineering. Civil Engineering Department is in
the first year. At present, the strength of the department is 60 students. We have Strength
of Materials lab with all modern high capacity equipments. The vision of our Department is
to throw light on the various developments in the field of Civil Engineering.</p>
<h2>This is a header 1</h2>
<hr />
<p>You can see that the style sheet formats the text</p>
<p><a href="http://www.google.co.in/" target="_blank">This is a link</a></p>
</body>
</html>
external_style.css
<style>
h2 {color:maroon; font-size:20pt}
hr {color:navy}
a:link {color:green}
a:visited {color:yellow}
a:hover {color:red}
a:active {color:blue}
</style>
OUTPUT
EXP.NO:6
DATE:
SERVLET PROGRAMMING
Programs in Java using Servlets
Aim :To write a html program for invoking servlet using html.
PROCEDURE
STEP 1:
Open Netbeans IDE and Select File->New project.
STEP 2: Select Java Web->Web Application, then click on Next .Give a Filename to
your project and click on next.
STEP 3:
Select Glass Fish Server3.1 and choose Java EE5 Web , then click Finish.
STEP 4: To create a Servlet, Open Source Package and then right click on default
package, Select New->Servlet. Give a File Name to the Servlet Class file and click next.
STEP 5: Choose Add information to deployment descriptor (web.xml) on check
box to add the servlet information in web.xml file.
STEP 6: To create an HTML file , right click on Web Pages->New->HTML. Give a File
Name and click Finish.
STEP 7:
Edit web.xml file by Changing your html file name in welcome-file.
STEP 11: After completing all these steps, Select File->Save for saving the Project.
STEP 12: Select Project tab->WebApplication and then right click, select Run.
Problem Statement
•
•
•
•
•
Create a Html with Username and password
Create the class as Loginservlet.
Enter the username and password in the form.
If username and password are correct then the “welcometo my web page” servlet
page is done .Use RequestDispatcher is used to transfer messages efficiently.
Else the message “Loginpage:” will be displayed.
PROGRAM
Newhtml.html
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form name="logonform" action="LoginServlet11" method="get" >
Username: <input type="text" name="username"/>
<br/>
Password:<input type="password" name="password"/>
<br/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
LoginServlet11.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet11 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter writer = response.getWriter();
// read form fields
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username!=null && password!=null &&
username.equals("vels") &&password.equals("vels")) {
// build HTML code
RequestDispatcher rd = request.getRequestDispatcher("WelcomeServlet");
rd.forward(request, response);
}
else
System.out.println("Username or Password incorrect");
RequestDispatcher rd = request.getRequestDispatcher("newhtml.html");
rd.include(request, response);
}
}
WelcomeServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Welcome</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<P>Welcome to My Website</P>");
out.println("</BODY>");
out.println("</HTML>");
}
}
OUTPUT
EXP.NO:7
DATE:
SERVLET PROGRAMMING
Three-tier applications using servlets, JSP and Databases.
Aim: To write a Java Servlet program to connect to a database and store the registration
details in a database table.
PROCEDURE
STEP 1:
Open Netbeans IDE and Select File->New project.
STEP 2: Select Java Web->Web Application, then click on Next .Give a Filename to
your project and click on next.
STEP 3:
Select Glass Fish Server3.1 and choose Java EE5 Web , then click Finish.
STEP 4: To create a Servlet, Open Source Package and then right click on default
package, Select New->Servlet. Give a File Name to the Servlet Class file and click next.
STEP 5: Choose Add information to deployment descriptor (web.xml) on check
box to add the servlet information in web.xml file.
STEP 6: To create a JSP file , right click on Web Pages->New->JSP. Give a File Name
and click Finish.
STEP 7:
Edit web.xml file by Changing your jsp file name in welcome-file.
STEP 8: To create SQL Database, Choose Services tab and then select Database>Java DB->sample.
STEP 9:
Right click on sample and then select Connect.
STEP 10: Select jdbc: derby: //localhost:1527/sample [app on APP] and then right
click , choose Create Table.
STEP 11: After completing all these steps, Select File->Save for saving the Project.
STEP 12: Select Project tab->WebApplication and then right click, select Run.
PROBLEM STATEMENT:
1) Create a Main Page with following frames
o A Frame which Displays the Logo and Login Link
o A frame whichdisplays the Home page of VELS UNIVERSITY
o A frame which displays the links for Registration and Home Page
2) Create a Login page using JSP for getting the Username and Password with Submit
Button
3) Create a Login Registration Page which has Username, Password, Name, Gender,
Department and Submit button.
4) Once data is submitted to the data base Use RequestDispatcher to call the Login Page
5) When the user Login, the data should be validated with the database and if incorrect
should display the error message.
Index.jsp
<html>
<frameset rows="35%,*%">
<frame src="logo.jsp">
<frameset cols="25%,75%">
<frame src="link.jsp">
<frame src="UserHome.jsp" name="content">
</frameset>
</frameset>
</html>
Logo.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<right>
<a href="login.jsp" style=alignment-adjust: text-align: right target
="content">Login</a></right>
<center><img src="vels.png" ></center>
</body>
</html>
Link.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<a href="UserHome.jsp" target ="content">Home</a><br>
<a href="insert.jsp" target ="content">Registration</a>
</body>
</html>
UserHome.jsp
<html>
<head>
<title>VISTAS</title>
<style>
.DIV1
{
height:50px;
background-color:blue;
width:100%;
}
</STYLE>
</head>
<body>
<h2>Vael?s Educational Trust</h2>
<p>Vael?s Educational Trust was established in 1992 with the aim of transforming an
individual into a complete man with character and ability committed to national
service
and development. The trust was founded by Dr. Ishari K Ganesh, M.Com,
MBA, B.L, (M.L), Ph.D,
a visionary and an eminent educationist, in fond memory
of his father Shri.Isari Velan,
a former minister in the popular Govt. of Dr. MGR.
Vael?s Educational Trust has always
served to take education to the thresholds
of first generation learners and weaker sections
of the society.
</p>
<h2>The University</h2>
<p>
The University status was conferred to Vel's Group of Institutions, by the Ministry of
Human Resource Development, Govt. of India. As a logical consequence of this, the
founder
Chairman Dr.Ishari K.Ganesh has become the President/Chancellor and
now he leads the
implementation of strategic plan that aims to shape the institute's
future growth.
He visualizes an University which will be globally more competitive
and internationally
recognized institution.
The University is governed by
Governing Board or otherwise
known as Board of Management and this is the
highest statutory body of this University.
The members of this Board is drawn from
various agencies. The Board has members representing
University Grants
Commission, Govt. of India, Industry, Eminent persons out side Academia,
Senior
Academic persons and senior officials of the University. The President/Chancellor is
the Chairman of the Board and the board meets periodically to frame policies and
programmes
for the growth and improvement of VISTAS.
</p>
</html>
</body>
</html>
Login.jsp
<html>
<body>
<form method="post" action="loginservlet">
<table border='1' align="center">
<tbody>
<tr>
<td width="170" style="width: 170px">USERNAME</td>
<td width="349"><input type="text" name="UNAME"
size="20">
</td>
</tr>
<tr>
<td width="170">PASSWORD</td>
<td width="349"><input type="text" name="PASS" size="20">
</td>
</tr>
<tr>
<td width="170"></td>
<td width="349"><input type="submit" name="SUBMIT"
value="SUBMIT">
</td>
</tr>
</td>
</table>
</form>
</body>
</html>
Insert.jsp
<html>
<head>
<title>File1</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<form method="post" action="insertservlet">
<table border='1' align="center">
<tbody>
<tr>
<td width="170" style="width: 170px">USERNAME</td>
<td width="349"><input type="text" name="UNAME"
size="20">
</td>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<td width="170">PASSWORD</td>
<td width="349"><input type="text" name="PASS" size="20">
</td>
<td width="170">NAME</td>
<td width="349"><input type="text" name="NAME"
size="20">
</td>
<td width="170">GENDER</td>
<td width="349"><input type="radio" name="G" value="Male"
id="Male">Male <input type="radio" name="G"
value="female">Female
</td>
<td width="170">DEPARTMENT</td>
<td width="349"><select name="dept"><option
value="ECE">ECE</option>
<option value="CSE">CSE</option>
<option value="IT">IT</option>
<option value="CIVIL">CIVIL</option>
</select>
</td>
<td width="170"></td>
<td width="349"><input type="submit" name="SUBMIT"
value="SUBMIT">
</td>
Insertservlet.java
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class insertservlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String uname=request.getParameter("UNAME");
String pass=request.getParameter("PASS");
String name=request.getParameter("NAME");
String gen=request.getParameter("G");
String dept=request.getParameter("dept");
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con= DriverManager.getConnection("jdbc:derby://
localhost:1527/sample1","vels","vels");
PreparedStatement ps=con.prepareStatement("insert into
REGISTERUSER values(?,?,?,?,?)");
ps.setString(1, uname);
ps.setString(2, pass);
ps.setString(3, name);
ps.setString(4, gen);
ps.setString(5, dept);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
int i=ps.executeUpdate();
if(i!=0)
{
RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
out.println("<font color=red>Please login with registered user
Id</font>)");
rd.include(request, response);
}
else
{
RequestDispatcher rd = request.getRequestDispatcher("insert.jsp");
out.println("<font color=red>Not Reguistered Please try
again</font>)");
rd.include(request, response);
}
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Loginservlet.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class loginservlet
*/
public class loginservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public loginservlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// TODO Auto-generated method stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String uname=request.getParameter("UNAME");
String pass=request.getParameter("PASS");
//select * from vels where username=? and password=?
HttpSession session=request.getSession();
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con=DriverManager.getConnection
("jdbc:derby://localhost:1527/sample1","vels","vels");
PreparedStatement ps=con.prepareStatement("select * from
registeruser where uname=? and pass=?");
ps.setString(1, uname);
ps.setString(2, pass);
ResultSet rs=ps.executeQuery();
if(rs.next())
{
System.out.println(rs.getString(1));
session.setAttribute("uname", uname);
session.setAttribute("pass", pass);
session.setAttribute("name", rs.getString(3));
session.setAttribute("dept", rs.getString(5));
getServletContext().getRequestDispatcher
("/UserHome.jsp").forward(request, response);
}
else
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
RequestDispatcher rd =
request.getRequestDispatcher("login.jsp");
out.println("<font color=red>Please login with registered
user id</font>)");
rd.include(request, response);
}
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
EXP.NO:8
DATE:
JAVA PROGRAMS – NETWORKING
Uniform Resource Locator
Exercise 8:Uniform Resource Locator
Aim: To create a java Program to provide the details for the given URL.
PROCEDURE:
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project and click on Finish.
STEP4:To RUN the program
Type the argument value http://www.velsuniv.ac.in by
right click PROJECT-> Set configuration ->customize->arguments
PROBLEM STATEMENT:
1. Create a java and import necessary packages.
2. Declare a variable of string datatype to get url details.
3. Create an object of url and print url, protocol, hostname, port number, file name.
PROGRAM
package ex8;
import java.net.*;
public class EX8 {
public static void main(String args[]) {
for (int i = 0; i < args.length; i++) {
try {
URL u = new URL(args[i]);
System.out.println("The URL is " + u);
System.out.println("The scheme is " + u.getProtocol( ));
System.out.println("The user info is " + u.getUserInfo( ));
String host = u.getHost( );
if (host != null) {
int atSign = host.indexOf('@');
if (atSign != -1)
host = host.substring(atSign+1);
System.out.println("The host is " + host);
}
else {
System.out.println("The host is null.");
}
System.out.println("The port is " + u.getPort( ));
System.out.println("The path is " + u.getPath( ));
System.out.println("The ref is " + u.getRef( ));
System.out.println("The query string is " + u.getQuery( ));
} // end try
catch (MalformedURLException e) {
System.err.println(args[i] + " is not a URL I understand.");
}
System.out.println( );
} // end for
} // end main
} //
OUTPUT
The URL is http://www.velsuniv.ac.in
The scheme is http
The user info is null
The host is www.velsuniv.ac.in
The port is -1
The path is
The ref is null
The query string is null
EXP.NO:9
DATE:
JAVA PROGRAMS – NETWORKING
Socket Programming
Exercise 9:Socket Programming
Aim: To create a JAVA program and to implement a Server-socket connection.
PROCEDURE:
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project as CLIENTand click on Finish
STEP4:Select Java ->Java Application, then click on Next .
STEP5:Give a name to your project as SERVERand click on Finish
STEP6 : Write the client and java programs in the respective Java Files
STEP7: Compile both of them on two different terminals or tabs
STEP8: Run the Server program first
STEP 9: Then run the Client program
STEP 10: Type messages in the Client Window which will be received and showed
by the Server Window simultaneously.
STEP11: Type Over to end.
PROGRAM:
Client.java
import java.net.*;
import java.io.*;
public class Client1
{
// initialize socket and input output streams
private Socket socket
= null;
private DataInputStream input = null;
private DataOutputStream out = null;
// constructor to put ip address and port
public Client1(String address, int port)
{
// establish a connection
try
{
socket = new Socket(address, port);
System.out.println("Connected");
// takes input from terminal
input = new DataInputStream(System.in);
// sends output to the socket
out = new DataOutputStream(socket.getOutputStream());
}
catch(UnknownHostException u)
{
System.out.println(u);
}
catch(IOException i)
{
System.out.println(i);
}
// string to read message from input
String line = "";
// keep reading until "Over" is input
while (!line.equals("Over"))
{
}
}
try
{
line = input.readLine();
out.writeUTF(line);
}
catch(IOException i)
{
System.out.println(i);
}
// close the connection
try
{
input.close();
out.close();
socket.close();
}
catch(IOException i)
{
System.out.println(i);
}
public static void main(String args[])
{
Client1 client = new Client1("192.168.3.125", 5000);
}
}
Server.java
import java.net.*;
import java.io.*;
public class Server1
{
//initialize socket and input stream
private Socket
socket = null;
private ServerSocket server = null;
private DataInputStream in
= null;
// constructor with port
public Server1(int port)
{
// starts server and waits for a connection
try
{
server = new ServerSocket(port);
System.out.println("Server started");
System.out.println("Waiting for a client ...");
socket = server.accept();
System.out.println("Client accepted");
// takes input from the client socket
in = new DataInputStream(
new BufferedInputStream(socket.getInputStream()));
String line = "";
// reads message from client until "Over" is sent
while (!line.equals("Over"))
{
try
{
line = in.readUTF();
System.out.println(line);
}
catch(IOException i)
{
System.out.println(i);
}
}
System.out.println("Closing connection");
// close connection
socket.close();
in.close();
}
}
catch(IOException i)
{
System.out.println(i);
}
public static void main(String args[])
{
Server1 server = new Server1(5000);
}
}
OUTPUT:
Serverrun:
Server started
Waiting for a client...
Client accepted
Hello welcome
Clientrun:
Connected
Hello welcome
EXP.NO:10
DATE:
APPLETS
Exercise 10:Applets
Aim: To write a java program to create the applets.
PROCEDURE:
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project and click on Finish.
PROBLEM STATEMENT:
1.Write a HTML applet tag with code set, class name, and comment the tag.
2.Import all necessary packages and classes.
3.Define a class that extends applet and implements action listener and item listener.
4.Declare an array of buttons to set colors , two check boxes for foreground and
background colors.
5.Declare a text area to hold the text, a check box group for check boxes.
6. Declare three panels, button panel, palette panel and check pael.
7. Declare a string, color.
8.Display the result.
PROGRAM:
package colour;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Colour extends JApplet implements ActionListener
{
JPanel p,p1;
JButton b,b1,b2,b3;
Checkbox c,c1;
TextArea area;
Color d=new Color(255,0,0);
Color d1=new Color(0,255,0);
Color d2=new Color(0,0,255);
Color d3=new Color(255,177,76);
GridLayout g;
public void init()
{
p=new JPanel();
p1=new JPanel();
g=new GridLayout(2,2);
p1.setLayout(g);
b=new JButton();
b1=new JButton();
b2=new JButton();
b3=new JButton();
b.setBackground(d);
b1.setBackground(d1);
b2.setBackground(d2);
b3.setBackground(d3);
area=new TextArea(" Welcome To Colour Palate ",25,25);
CheckboxGroup cbg=new CheckboxGroup();
c=new Checkbox(" ForeGround ",cbg,true);
c1=new Checkbox(" BackGround ",cbg,false);
p.add(c);
p.add(c1);
p.add(area);
p1.add(b);
p1.add(b1);
p1.add(b2);
p1.add(b3);
p.add(p1);
getContentPane().add(p);
b.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object obj=e.getSource();
if(obj==b)
{
if(c.getState()==true)
area.setForeground(d);
else
area.setBackground(d);
}
if(obj==b1)
{
if(c.getState()==true)
area.setForeground(d1);
else
area.setBackground(d1);
}
if(obj==b2)
{
if(c.getState()==true)
area.setForeground(d2);
else
area.setBackground(d2);
}
if(obj==b3)
{
if(c.getState()==true)
area.setForeground(d3);
else
area.setBackground(d3);
}}}
OUTPUT
EXP.NO:11
DATE:
DATAGRAM SOCKETS AND DATAGRAM PACKETS
Aim: To write a java program to create a simple chat application with datagram sockets
and Packets
PROCEDURE:
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project as datasocketand click on Finish
STEP4:Select Java ->Java Application, then click on Next .
STEP5:Give a name to your project as SERVERand click on Finish
PROBLEM STATEMENT:
Server Side
Import net and io packages and class
Create a datagram socket and datagram packet
While client send datagram packet to server listen to client port
Get the IP address into a string
Display the string
Client Side
Import net and io packages
Create a datagram socket and datagram packet
Get input from the user and convert the string into a datagram packet
send the datagram packet to the server through serve port
Program:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Arrays;
public class datasocket
{
public static void main(String[] args) throws IOException
{
// Constructor to create a datagram socket
DatagramSocket socket = new DatagramSocket();
InetAddress address = InetAddress.getByName("localhost");
int port = 5252;
byte buf[] = { 12, 13 };
byte buf1[] = new byte[2];
DatagramPacket dp = new DatagramPacket(buf, 2, address, port);
DatagramPacket dptorec = new DatagramPacket(buf1, 2);
// connect() method
socket.connect(address, port);
// isBound() method
System.out.println("IsBound : " + socket.isBound());
// isConnected() method
System.out.println("isConnected : " + socket.isConnected());
// getInetAddress() method
System.out.println("InetAddress : " + socket.getInetAddress());
// getPort() method
System.out.println("Port : " + socket.getPort());
// getRemoteSocketAddress() method
System.out.println("Remote socket address : " +
socket.getRemoteSocketAddress());
// getLocalSocketAddress() method
System.out.println("Local socket address : " +
socket.getLocalSocketAddress());
// send() method
socket.send(dp);
System.out.println("...packet sent successfully....");
// receive() method
socket.receive(dptorec);
System.out.println("Received packet data : " +
Arrays.toString(dptorec.getData()));
// getLocalPort() method
System.out.println("Local Port : " + socket.getLocalPort());
// getLocalAddress() method
System.out.println("Local Address : " + socket.getLocalAddress());
// setSOTimeout() method
socket.setSoTimeout(50);
// getSOTimeout() method
System.out.println("SO Timeout : " + socket.getSoTimeout());
}
}
Server:
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
public class smallserver {
public static void main(String[] args) throws IOException {
DatagramSocket ds = new DatagramSocket(5252);
byte buf[] = new byte[2];
byte send[] = { 13, 18 };
DatagramPacket dp = new DatagramPacket(buf, 2);
ds.receive(dp);
DatagramPacket senddp = new DatagramPacket(send, 2,
dp.getAddress(), dp.getPort());
ds.send(senddp);
}
}
OUTPUT
IsBound : true
isConnected : true
InetAddress : localhost/127.0.0.1
Port : 5252
Remote socket address : localhost/127.0.0.1:5252
Local socket address : /127.0.0.1:53358
...packet sent successfully....
Received packet data : [13, 18]
Local Port : 53358
Local Address : /127.0.0.1
SO Timeout : 50
BUILD SUCCESSFUL (total time: 0 seconds)
EXP.NO:12.A
DATE:
VARIOUS LAYOUTS
FLOW LAYOUT
AIM: To write a java program to demonstrate the Flow Layout
PROCEDURE
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project and click on Finish.
PROBLEM STATEMENT
• Write a html applet tag with code set to class name and comment it
• Import all necessary packages and classes
• Define a class that extends Applet
• Declare an array of buttons and three panels
• In the init() method of the applet do the following:
i) Set the layout of the applet to Grid layout that can hold three columns
ii) Create the array of buttons
iii) Add a panel, set the layout to Flow layout to add buttons from the center
iv) Add the buttons to the panel
v) Similarly create two more panels and set layout to flow layout to add the
buttons from the left and right of the flow layout
vi) Add the buttons in to these panels
PROGRAM:
Program
/* <applet code=FlowLayoutApplet height=400 width=600></applet>*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class FlowLayoutApplet extends Applet
{
Button[] b;
Panel p1,p2,p3;
public void init()
{
setLayout(new GridLayout(3,1));
p1 = new Panel();
p1.setLayout(new FlowLayout(FlowLayout.RIGHT));
add(p1);
p2 = new Panel();
p2.setLayout(new FlowLayout(FlowLayout.LEFT));
add(p2);
p3 = new Panel();
p3.setLayout(new FlowLayout(FlowLayout.CENTER));
add(p3);
b = new Button[15];
for(int i=0;i<15;i++)
{
b[i] = new Button();
b[i].setLabel("Button"+(i+1));
p1.add(b[i]);
}
for(int i=0;i<15;i++)
{
b[i] = new Button();
b[i].setLabel("Button"+(i+1));
p2.add(b[i]);
}
for(int i=0;i<15;i++)
{
b[i] = new Button();
b[i].setLabel("Button"+(i+1));
p3.add(b[i]);
}
}
}
OUTPUT
EXP.NO:12.B
DATE:
VARIOUS LAYOUTS
BORDER LAYOUT
Aim : To write a java program demonstrating the Border Layout
PROCEDURE
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project and click on Finish.
PROBLEM STATEMENT:
•
•
•
•
•
•
•
•
Include the applet tag with code set to the class name of the applet as comment
Import all the required packages and classes
Define class which extends Applet and implements ActionListener
Declare buttons green, red, blue, red and font
Declare msg of type String and initialize to "VISTAS"
Declare a Textarea area
In the init method of the applet, do the following
i) Set the layout to border layout
ii) Create area object and set its text to msg and add it to the center of the
borderlayout
iii) Create green button and add it to the north of borderlayout. Similarly, create red,
blue,font buttons and add them to south,east, west of border layout.
iv) Add action listener to all the buttons
In the actionperformed method do the following
i) Get the action command of a button pressed in a string str
ii) If str is equal to any one of the color button's text then set the foreground to that
color.
iii) If str is equal to font then create a new font of type Garmond and set the area's
font to the newly created font
iv) Repaint the applet
write the paint method with no body (empty paint method)
PROGRAM
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code=BorderLayoutApplet width=300 height=100>
</applet>*/
public class BorderLayoutApplet extends Applet implements ActionListener{
Button green=new Button("green");
Button red=new Button("red");
Button blue=new Button("blue");
Button font=new Button("font");
String msg="VISTAS";
TextArea area;
public void init()
{
setLayout(new BorderLayout());
area = new TextArea();
area.setText(msg);
add(green,BorderLayout.NORTH);
add(red,BorderLayout.SOUTH);
add(blue,BorderLayout.EAST);
add(font,BorderLayout.WEST);
add(area,BorderLayout.CENTER);
green.addActionListener(this);
red.addActionListener(this);
blue.addActionListener(this);
font.addActionListener(this);
}
public void actionPerformed (ActionEvent a)
{
String str= a.getActionCommand();
if(str.equals("green"))
{
area.setForeground(Color.green);
}
else if(str.equals("red"))
{
area.setForeground(Color.red);
}
else if(str.equals("blue"))
{
area.setForeground(Color.blue);
}
else
{
Font myfont = new Font("Garamond",Font.BOLD,25);
area.setFont(myfont);
area.setForeground(Color.cyan);
}
repaint();
}
public void paint(Graphics g)
{} }
OUTPUT
EXP.NO:12.C
DATE:
VARIOUS LAYOUTS
GRID LAYOUT
Aim : To write a java program to demonstrate the Grid Layout
PROCEDURE
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project and click on Finish.
PROCEDURE
•
•
•
•
•
•
Write an applet tag with code property set to class name and comment it
import all the necessary packages
Define a class which extends Applet
Declare any number of buttons
In the init() method do the following:
i) Create a panel
ii) create the buttons
iii) set the layout of the panel to Gridlayout
iv) add the buttons to the panel
v) set the layout of the applet to borderlayout
vi) add the panel to the center of the border layout
Write empty paint() method
PROGRAM
Program
/*<applet code=GridLayoutApplet width=100 height=100>
</applet>*/
import java.applet.Applet;
import java.awt.*;
public class GridLayoutApplet extends Applet
{
private Button one,two,three,four,five,six,seven,eight,nine,ten;
public void init()
{
Panel panel=new Panel();
one=new Button("1");
two=new Button("2");
three=new Button("3");
four=new Button("4");
five=new Button("5");
six=new Button("6");
seven=new Button("7");
eight=new Button("8");
nine=new Button("9");
ten=new Button("10");
panel.setLayout(new GridLayout(3,0,10,10));
panel.add(one);
panel.add(two);
panel.add(three);
panel.add(four);
panel.add(five);
panel.add(six);
panel.add(seven);
panel.add(eight);
panel.add(nine);
panel.add(ten);
setLayout(new BorderLayout());
add(panel,BorderLayout.CENTER);
}
public void paint(Graphics g)
{}
}
OUTPUT
EXP.NO:12.D
DATE:
VARIOUS LAYOUTS
GRIDBAG LAYOUT
Aim : To write a java program to demonstrate the Gridbag Layout
PROCEDURE
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project and click on Finish.
PROCEDURE
•
•
•
•
•
Write a html applet tag with code property set to class name and comment the tag
Import all necessary packages
Define a class which extends applet class
Declare all the necessary awt controls to be included in the purchase form
In the init() method, do the following:
i) Create a gridbag layout and set the applet's layout to gridbag layout
ii) Create a gridbag constraint
iii) Create a awt control
iv) Set the gridbag constraints for this control
v) Add the control to the applet
vi) Similarly do the steps from iii) to v) for all other control
PROGRAM
/** <applet code = PurchaseApplet width = 600 height = 400>
</applet> */
import java.awt.*;
import java.applet.Applet;
public class PurchaseApplet extends Applet
{
Panel ButtonPanel;
Label title,name,address,payment,phone,city,state;
TextField namefield,addressfield,cityfield,statefield;
Choice paymentChoice;
Button paymentButton,cancelButton;
public void init()
{
ButtonPanel = new Panel();
title=new Label("Purchase Form");
name=new Label("Name");
address=new Label("Address");
payment=new Label("payment");
phone=new Label("phone");
city=new Label("city");
state=new Label("state");
namefield=new TextField(25);
addressfield=new TextField(30);
cityfield=new TextField(20);
statefield=new TextField(20);
paymentChoice=new Choice();
paymentButton=new Button("purchase");
cancelButton=new Button("cancel");
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
setLayout(gbl);
paymentChoice.add("visa");
paymentChoice.add("master card");
paymentChoice.add("cod");
title.setFont(new Font("Times-Roman",Font.BOLD+Font.ITALIC,16));
gbc.anchor=GridBagConstraints.NORTH;
gbc.gridwidth=GridBagConstraints.REMAINDER;
add(title,gbc);
gbc.fill=GridBagConstraints.HORIZONTAL;
gbc.insets=new Insets(10,0,10,0);
gbc.gridwidth = 1;
add(name,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
add(namefield,gbc);
gbc.insets=new Insets(0,0,10,0);
gbc.gridwidth=1;
add(address,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
add(addressfield,gbc);
gbc.gridwidth=1;
add(city,gbc);
add(cityfield,gbc);
add(state,gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;
add(statefield,gbc);
gbc.fill = GridBagConstraints.NONE;
gbc.gridwidth=1;
add(payment,gbc);
gbc.gridwidth = GridBagConstraints.REMAINDER;
add(paymentChoice,gbc);
ButtonPanel.add(paymentButton);
ButtonPanel.add(cancelButton);
gbc.anchor=GridBagConstraints.SOUTH;
gbc.gridwidth = 4;
add(ButtonPanel,gbc);
}
}
OUTPUT
EXP.NO:12.E
DATE:
VARIOUS LAYOUTS
CARD LAYOUT
AIM :
To write a java program to demonstrate the Card Layout
PROCEDURE
STEP1:Open Netbeans IDE and Select File->New project.
STEP2:Select Java ->Java Application, then click on Next .
STEP3:Give a name to your project and click on Finish.
PROCEDURE
•
•
•
•
•
•
Write a html applet tag with code set class name and comment the tag
Import all necessary packages and classes
Define a class that extends applet and implements action listener
Declare buttons tiny, large, medium, and small
Create panels for card layout and for cards of buttons
In the init() method, do the following:
i) Create the card layout
ii) Create the cardpanel and set its layout to card layout
iii) Create other panels and set their layout to border layout
iv) Create buttons and change their fonts to vriuos font face and sizes according to
the button name
v) Add action listener to the buttons and each button to one panel of appropriate
name
vi) Add the panels to the card panel
vii) Set the layout of the applet to border layout and add card panel to the applet
• In the actionPerformed() method, move to the next card in the card panel
PROGRAM
*<applet code=cardLayoutApplet width=600 height=400>
</applet>*/
import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.ActionListener;
public class cardLayoutApplet extends Applet implements ActionListener
{
private Button tiny,large,medium,small;
private Panel cardpanel=new Panel();
private Panel tinypanel=new Panel();
private Panel smallpanel=new Panel();
private Panel medpanel=new Panel();
private Panel largepanel=new Panel();
private CardLayout card=new CardLayout(10,5);
public void init()
{
cardpanel.setLayout(card);
tinypanel.setLayout(new BorderLayout());
smallpanel.setLayout(new BorderLayout());
medpanel.setLayout(new BorderLayout());
largepanel.setLayout(new BorderLayout());
tiny=new Button("Tiny CardLayout");
small=new Button("Small CardLayout");
medium=new Button("Medium CardLayout");
large=new Button("Large CardLayout");
tiny.setFont(new Font("Helvetica",Font.BOLD,20));
small.setFont(new Font("Times-Roman",Font.BOLD,12));
medium.setFont(new Font("Arial",Font.BOLD,23));
large.setFont(new Font("Courier",Font.BOLD,32));
tiny.addActionListener(this);
small.addActionListener(this);
medium.addActionListener(this);
large.addActionListener(this);
tinypanel.add(tiny,BorderLayout.CENTER);
smallpanel.add(small,BorderLayout.CENTER);
medpanel.add(medium,BorderLayout.CENTER);
largepanel.add(large,BorderLayout.CENTER);
cardpanel.add("tiny",tinypanel);
cardpanel.add("small",smallpanel);
cardpanel.add("medium",medpanel);
cardpanel.add("large",largepanel);
setLayout(new BorderLayout());
add(cardpanel,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
card.next(cardpanel);
}
}
OUTPUT
Download