JAVA PGM USING COMPONENTS:
import [Link].*;
import [Link].*;
/*<applet code="[Link]" width=60 height=250></applet>*/
public class SimpleApplet extends Applet
{Button b1;
public void init( )
{setLayout(new GridLayout(20,2));
Label l1=new Label("Name:",[Link]);
add(l1);
TextField t1=new TextField();
add(t1);
TextArea ta=new TextArea(5,8);
Label l2=new Label("ABOUT",[Link]);
[Link]("Example\nfor the\nScroll bar\nusing \nText Area");
add(l2);add(ta);
[Link](false);
setLayout(new GridLayout(25,30));
Checkbox c1=new Checkbox("IP",true);
Checkbox c2=new Checkbox("OS");
add(c1);
add(c2);
Choice color=new Choice();
[Link]("RED");
[Link]("BLUE");
[Link]("GREEN");
add(color);
setLayout(new FlowLayout([Link]));
b1=new Button("OK");
add(b1);
}}
FLOW LAYOUT:
import [Link].*;
class fl extends Frame
{fl(String s){
super(s);
setSize(300,140);
setLayout(new FlowLayout());
for(int i=1;i<=3;i++)
add(new Button("Button No"+i));
setVisible(true);}}
class test
{
public static void main(String args[])
{fl f=new fl("FLOW LAYOUT"); }}
1
BORDER LAYOUT:
import [Link].*;
class bl extends Frame
{bl(String s)
{super(s);
setSize(300,140);
add(new Button("North"),[Link]);
add(new Button("South"),[Link]);
add(new Button("East"),[Link]);
add(new Button("West"),[Link]);
add(new Button("<--------------->"),[Link]);
setVisible(true);}}
class test2
{public static void main(String args[])
{bl b=new bl("BORDER LAYOUT");
}}
GRID LAYOUT:
import [Link].*;
class gl extends Frame
{
gl(String s)
{
super(s);
setSize(300,140);
setLayout(new GridLayout(3,4));
for(int i=1;i<=3;i++)
add(new Button("Button No"+i));
setVisible(true);
}}
class test3
{
public static void main(String a[])
{
gl g=new gl("GRID LAYOUT");
}}
CARD LAYOUT:
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="card" width=300 height=300>
</applet>*/
public class card extends Applet implements ActionListener
{
2
Button b1,b2;
CardLayout card1;
Panel pan,pan1,pan2;
public void init()
{
pan=new Panel();
add(pan);
card1=new CardLayout();
[Link](card1);
pan1=new Panel();
add(pan1);
pan2=new Panel();
b1=new Button("Button1");
b2=new Button("Button2");
[Link](this);
[Link](this);
add(b1);
add(b2);
[Link]("Button1",b1);
[Link]("Button2",b2);
[Link](pan1,"Button1");
[Link](pan2,"Button2");
}
public void actionPerformed(ActionEvent ae)
{
[Link](pan);
repaint();
}
public void paint(Graphics g)
{
}
}
GRID BAG LAYOUT:
import [Link].*;
import [Link].*;
import [Link].*;
/* <applet code="Gbag" width=400 height=200>
</applet>
*/
public class Gbag extends Applet
{
public void init()
{
GridBagLayout gb=new GridBagLayout();
setLayout(gb);
3
GridBagConstraints Cons1=new GridBagConstraints();
[Link]=[Link];
[Link]=1;
[Link]=1;
[Link]=0;
[Link]=0;
GridBagConstraints Cons2=new GridBagConstraints();
[Link]=[Link];
[Link]=1;
[Link]=1;
[Link]=1;
[Link]=0;
GridBagConstraints Cons3=new GridBagConstraints();
[Link]=[Link];
[Link]=2;
[Link]=2;
[Link]=0;
[Link]=1;
Button b1=new Button("one");
Button b2=new Button("two");
Button b3=new Button("three");
[Link](b1,Cons1);
add(b1);
[Link](b2,Cons2);
add(b2);
[Link](b3,Cons3);
add(b3);
} }
COLOR PALETTE:
import [Link].*; import [Link].*; import [Link].*;
/*<applet code=palette height=600 width=600></applet>*/
public class palette extends Applet implements ActionListener,ItemListener
{Button[] Colors;
Checkbox fg,bg;
TextArea wa;
CheckboxGroup cbg;
Panel buttonpanel,checkpanel,palettepanel;
String color;
public void init()
{buttonpanel=new Panel();
[Link](new GridLayout(3,3));
4
Colors=new Button[9];
Colors[0]=new Button("RED");
Colors[1]=new Button("GREEN");
Colors[2]=new Button("BLUE");
Colors[3]=new Button("CYAN");
Colors[4]=new Button("ORANGE");
Colors[5]=new Button("WHITE");
Colors[6]=new Button("BLACK");
Colors[7]=new Button("YELLOW");
Colors[8]=new Button("PINK");
for(int i=0;i<9;i++)
{Colors[i].addActionListener(this);
[Link](Colors[i]);}
checkpanel=new Panel();
[Link](new FlowLayout());
cbg=new CheckboxGroup();
fg=new Checkbox("FOREGROUND",cbg,true);
bg=new Checkbox("BACKGROUND",cbg,false);
[Link](this);
[Link](this);
[Link](fg); [Link](bg);
wa=new TextArea(8,40);
[Link](new Font("Garamond",[Link],20));
palettepanel=new Panel();
[Link](new BorderLayout());
[Link](wa,[Link]);
[Link](checkpanel,[Link]);
[Link](buttonpanel,[Link]);
add(palettepanel);}
public void itemStateChanged(ItemEvent ie){}
public void actionPerformed(ActionEvent ae)
{color=[Link]();
if([Link]()==true)
[Link](getColor());
if([Link]()==true)
[Link](getColor());}
public Color getColor()
{Color mycolor=null;
if([Link]("RED"))
mycolor=[Link];
if([Link]("GREEN"))
mycolor=[Link];
if([Link]("BLUE"))
mycolor=[Link];
if([Link]("CYAN"))
mycolor=[Link];
5
if([Link]("ORANGE"))
mycolor=[Link];
if([Link]("WHITE"))
mycolor=[Link];
if([Link]("BLACK"))
mycolor=[Link];
if([Link]("YELLOW"))
mycolor=[Link];
if([Link]("PINK"))
mycolor=[Link];
return mycolor;}}
URL:
import [Link].*;
import [Link].*;
import [Link].*;
class UrlDemo
{
public static void main(String[] arg)throws MalformedURLException,IOException
{
try
{
URL u= new URL("file:\\d:\\mathi\\[Link]");
URLConnection uc=[Link]();
InputStream in=[Link]();
int c;
while(( c=[Link]())!= -1)
[Link]((char)c);
[Link]("content length:"+[Link]());
[Link]("content type:"+[Link]());
[Link]("content encoding:"+[Link]());
[Link]("date:"+new Date([Link]()));
[Link]("modified date:"+new Date([Link]()));
[Link]("expired date:"+new Date([Link]()));
}
catch(MalformedURLException e)
{
[Link]("exception caught:"+e);
}
catch(IOException e1)
{
[Link]("exception caught:"+e1);
}
}}
6
WEB PAGE USING CASCADING STYLE SHEETS
[Link]
<html>
<frameset rows="70,*">
<frame src="[Link]" name="f1">
<frameset cols="35%,*">
<frame src="[Link]" name="f2">
<frame name="f3">
</frameset>
</frameset>
</html>
[Link]
<html>
<head><title>index</title>
</head>
<body bgcolor="magenta">
<center><h1>J2EE AND CASCADING STYLES</h1></center>
</body>
</html>
[Link]
<html>
<head> <title> linking...</title>
</head>
<body bgcolor="green">
<center>
<h2>DO U WANT TO KNOW..</h2>
<br>
<br>
<a href="[Link]" target="f3">J2EE</a><br>
<a href="[Link]" target="f3">STYLES</a><br>
<br>
<br>
click the appropriate option..<br><br>
<marquee>choose ur lovely platforms....</marquee>
</body>
</html>
[Link]
<html>
<head>
<title> working with style sheets </title>
<style type="text/css">
h1 {font-family:monotype corsiva}
7
h2 {background-color:green;background-repeat:repeat-x}
p {font-size:12pt;font-weight:bold;color:#23238e;border-style:groove}
ul {list-style-type:lower-roman}
</style>
</head>
<body bgcolor="pink">
<center>
<h1>WELCOME TO J2EE WORLD</h1>
<h2>Here, you will be able to create interactive server side programs....</h2><br>
<p>J2EE provides many platforms to create server side programming applications... each
application
provides many features... some of the platforms are as follows....</p>
<ul>
<li>SERVLETS</li>
<li>JMS</li>
<li>RMI</li>
<li>CORBA</li>
</ul>
<br><br><br>
<h1><marquee behaviour="right">Thanks for visiting....</marquee></h1>
</body>
</html>
[Link]
<html>
<head>
<title>external style sheets</title>
<link rel=stylesheet href="[Link]">
</head>
<body bgcolor="tee">
<center><h2>STYLE INFORMATION</h2></center>
<p>style sheets are powerful mechanism for adding styles to web [Link]
elements on a web page
can then be bound to the style [Link] advantages of a style sheet includes the ability to
make
global changes to all documents from a single location.</p><br>
style attributes are....<br>
<ul type="1" color="red">
<li>font attributes</li>
<li>text attributes</li>
<li>color and background attributes</li>
<li>margin attriutes</li>
</ul>
</body>
</html>
8
[Link]
p {font size:12pt;font-weight:bold}
body {margin-top=10%}
h2 {backgroung-image:url([Link]) }
DISPLAY HTML FORM USING SERVLET
HTML CODING:
<html>
<head><title>WELCOME TO MY SERVLET</title></head>
<body>
<form action="HelloServlet" method="post">
<center>
<br><br><br><br><br>
Name : <input type="text" name="name"><br><br>
Password: <input type="password" name="pwd"><br><br>
<input type="SUBMIT" name="submit" value="submit">
</center>
</form>
</body>
</html>
SERVLET CODING:
import [Link].*;
import [Link].*;
import [Link].*;
public class HelloServlet extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
PrintWriter out=[Link]();
[Link]("text/html");
String name=[Link]("name");
String pwd=[Link]("pwd");
[Link]("<html>");
[Link]("<body>");
[Link]("WELCOME!!!!!!" + name);
[Link]("</html>");
[Link]("</body>");
[Link]();
}
9
}
CHAT APPLICATION:
SERVER:
import [Link].*;
import [Link].*;
import [Link].*;
class Myserver
{
public static void main(String[] args)
{
try{
String str1,str2;
DatagramSocket ds;
DatagramPacket dp1,dp2;
InetAddress ia;
byte[] data1=new byte[1024]; byte[] data2=new byte[1024];
BufferedReader br1;
ds=new DatagramSocket(1500);
ia=[Link]();
br1=new BufferedReader(new InputStreamReader([Link]));
while(true)
{
[Link]("Enter the data to send");
str1=[Link]();
data1=[Link]();
dp1=new DatagramPacket(data1,[Link],ia,1700);
[Link](dp1);
if([Link]("bye"))
break;
dp2=new DatagramPacket(data2,[Link]);
[Link](dp2);
str2=new String([Link](),0,[Link]());
[Link]("The Received Data "+str2);
if([Link]("bye"))
break;
}
}
catch(BindException e)
{
[Link](e);
}
catch(SocketException e)
{
10
[Link](e);
}
catch(IOException e)
{
[Link](e);
}
}
}
CLIENT:
import [Link].*;
import [Link].*;
class Myclient
{
public static void main(String[] args)
{
String str1,str2;
DatagramSocket ds;
DatagramPacket dp1,dp2;
InetAddress ia;
byte[] data1=new byte[1024]; byte[] data2=new byte[1024];
BufferedReader br;
try
{
ds=new DatagramSocket(1700);
ia=[Link]();
br=new BufferedReader(new InputStreamReader([Link]));
while(true)
{
dp1=new DatagramPacket(data1,[Link]);
[Link](dp1);
str1=new String([Link](),0,[Link]());
[Link]("Length is "+ [Link]());
[Link]("The Received Data "+ str1);
if([Link]("bye"))
break;
[Link]("Enter the data to send");
str2=[Link]();
data2=[Link]();
dp1=new DatagramPacket(data2,[Link],ia,1500);
[Link](dp1);
}
}
catch(BindException e)
{
[Link](e);
11
}
catch(SocketException e)
{
[Link](e);
}
catch(IOException e)
{ [Link](e);
}
}
}
[Link]
<html>
<head><title>Image Map</title><head>
<body>
<h1 align="Center">India map<h1>
<center>
<img src="D:\second\[Link]" align="center" usemap="#Cities" height="672"
width="597" TITLE="INDIA MAP" ALT="IMAGE DOES NOT EXIST">
</center>
<Map Name="cities">
<area shape="CIRCLE" COORDS="240,556,25" href="d:\second\[Link]"
TITLE="This Connects to chennai" TABINDEX="1" >
<area shape="CIRCLE" COORDS="119,489,25" href="d:\second\[Link]"
TITLE="This Connects to goa" TABINDEX="1" >
<area shape="CIRCLE" COORDS="195,208,25" href="d:\second\[Link]"
TITLE="This Connects to delhi" TABINDEX="1" >
<area shape="CIRCLE" COORDS="409,335,25" href="d:\second\[Link]"
TITLE="This Connects to kolkatta" TABINDEX="1" >
</map>
</body>
</html>
[Link]
<html>
<head><title>CHENNAI</title></head>
<body BGCOLOR="BLUE" TEXT="WHITE">
<h1><MARQUEE> WELCOME TO SINGARA CHENNAI</MARQUEE></h1>
<BR><BR><BR><BR><BR>
<CENTER><h3>Intersting Places to visit in Chennai</h3></CENTER>
<CENTER>
<OL>
<LI>BEECH</LI>
<LI>VANDALOOR ZOO</LI>
<LI>SPENCER PLAZA</LI>
</OL>
12
<BR><BR><BR><BR><BR><BR>
<B>VISIT US AT........</B>
<BR>
[Link]
</CENTER>
</body></html>
[Link]
<html>
<head><title>GOA</title></head>
<body BGCOLOR="BLUE" TEXT="WHITE">
<h1><MARQUEE> WELCOME TO GOA</MARQUEE></h1>
<BR><BR><BR><BR><BR>
<CENTER><h3>Intersting Places to visit in goa</h3></CENTER>
<CENTER>
<OL>
<LI>BEECH</LI>
<LI>TEMPLES</LI>
</OL>
<BR><BR><BR><BR><BR><BR>
<B>VISIT US AT........</B>
<BR>
[Link]
</CENTER>
</body>
</html>
[Link]
<html>
<head><title>delhi</title></head>
<body BGCOLOR="BLUE" TEXT="WHITE">
<h1><MARQUEE> WELCOME TO DELHI</MARQUEE></h1>
<BR><BR><BR><BR><BR>
<CENTER><h3>Intersting Places to visit in delhi</h3></CENTER>
<CENTER>
<OL>
<LI>RED FORT</LI>
<LI>PARLIAMENT</LI>
<LI>TAJMAHAL</LI>
</OL>
<BR><BR><BR><BR><BR><BR>
<B>VISIT US AT........</B>
<BR>
[Link]
</CENTER>
</body></html>
13
[Link]
<html>
<head><title>KOLKATTA</title></head>
<body BGCOLOR="green" TEXT="WHITE">
<h1><MARQUEE> WELCOME TO KOLKATTA</MARQUEE></h1>
<BR><BR><BR><BR><BR>
<CENTER><h3>Intersting Places to visit in kolkatta</h3></CENTER>
<CENTER>
<OL>
<LI>VICTORIA PALACE</LI>
<LI>HOWRAH BRIDGE</LI>
</OL>
<BR><BR><BR><BR><BR><BR>
<B>VISIT US AT........</B>
<BR>
[Link]
</CENTER>
</body>
</html>
14
ONLINE EXAMINATION:
SERVLET:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet(name="Servlet", urlPatterns={"/Servlet"})
public class Servlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
PrintWriter out = [Link]();
try {
int mark=[Link]([Link]("total"));
[Link]("<center><h1>ONLINE EXAM RESULT</h1></center><br>");
[Link]("<h1>TOTAL MARK is:"+mark+"</h1>");
} finally {
[Link]();
}
}
HTML:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function ff()
{
var m=0;
if(document.f1.p1[2].checked==true)
m=m+1;
if(document.f1.p2[2].checked==true)
m=m+1;
if(document.f1.p3[2].checked==true)
m=m+1;
[Link]=m;
}
function reset()
15
{
[Link]=false;
[Link]=false;
[Link]=false;
m=0;
}
</script>
</head>
<body>
<center> <h1>ONLINE EXAMINATION</h1></center>
<form name="f1" method="get" action="NewServlet">
<ul><li>Which is the best hard disk seek time?<br>
<input type="radio" name="p1">30ms
<input type="radio" name="p1">20ms
<input type="radio" name="p1">5ms
</li>
<li>The Unix OS was developed using<br>
<input type="radio" name="p2">30ms
<input type="radio" name="p2">20ms
<input type="radio" name="p2">5ms
</li>
<li>A built in memory is termed as<br>
<input type="radio" name="p3">30ms
<input type="radio" name="p3">20ms
<input type="radio" name="p3">5ms
</li>
</ul>
<input type="text" name="total">
<input type="button" value="OK" onclick="ff()">
<input type="submit" value="submit">
<input type="button" value="reset" onclick="reset()">
</form>
</body>
</html>
16