Thursday, 26 May 2016

CREATE APPLET USING JAVA PROGRAM

import java.awt.*;
importjava.awt.event.*;
importjava.applet.*;
/*<applet code="exp" width=400 height=400></applet>*/
public class exp extends Applet implements ItemListener
{
intcurrcolor=5;
int flag=1;
String text="Click any of the buttons";
Button buttons[]=new Button[5];
String colours[]={"Red","Blue","Green","Yellow","Magenta"};
CheckboxGroupcbg=new CheckboxGroup();
Checkbox box1=new Checkbox("Background Color",cbg,true);
Checkbox box2=new Checkbox("Text Color",cbg,false);
public void init()
{
for(inti=0;i<5;i++)
{
buttons[i]=new Button(" ");
add(buttons[i]);
}
buttons[0].setBackground(Color.red);
buttons[1].setBackground(Color.blue);
buttons[2].setBackground(Color.green);
buttons[3].setBackground(Color.yellow);
buttons[4].setBackground(Color.magenta);
add(box1);
add(box2);
box1.addItemListener(this);
box2.addItemListener(this);
}
public void itemStateChanged(ItemEventev)
{ if(box1.getState()==true) flag=1;
else if(box2.getState()==true)
{
text="Default color is black";
flag=2;
}
repaint();
}
public void paint(Graphics g)
{
if(flag==2)
{ g.drawString(text,30,100);
switch(currcolor)
{
case 0: g.setColor(Color.red);
break;
case 1:
g.setColor(Color.blue);
break;
case 2: g.setColor(Color.green);
break;
case 3: g.setColor(Color.yellow);
break;
case 4: g.setColor(Color.magenta); break;
case 5: g.setColor(Color.black);
break;
}
g.drawString(text,30,100);
}
else if(flag==1)
{ g.drawString(text,30,100);
switch(currcolor)
{
case 0:
setBackground(Color.red);
break;
case 1: setBackground(Color.blue); break;
case 2: setBackground(Color.green); break;
case 3: setBackground(Color.yellow); break;
case 4: setBackground(Color.magenta); break;
case 5: setBackground(Color.white); break;
}
}
}
publicboolean action(Event e,Object o)
{
for(inti=0;i<5;i++)
{
if(e.target==buttons[i])
{
currcolor=i;
text="You have chosen "+colours[i];
repaint();
return true;
}
}
return false;
}
}









Labels:

DISPLAY BOOK INFORMATION USING XML FILE

PROGRAM:
bookstore.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="bookstore.xsl"?>

<bookstore>
<book>
  <title>Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>
<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>
<book>
  <title>Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>
</bookstore>
bookstore.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2> My Books collection</h2>
<table border="1">
<tr bgcolor="red">
<th align="left">title</th>
<th align="left">author</th>
</tr>
<xsl:for-each select="bookstore/book">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price &gt; 30">
<td bgcolor="yellow"><xsl:value-of select="author"/></td>
</xsl:when>
<xsl:when test="price &gt; 10">
<td bgcolor="lightgreen"><xsl:value-of select="author"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="author"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Labels:

PROGRAM USING JAVASCRIPT AND DHTML

PROGRAM
Login page (login.html)
<html>
 <head>
 <title>LOGIN</title>
 <script type="text/javascript">
  function validate()
  {
    var user_login=document.forms["myForm"]["user_login"].value;
    var password=document.forms["myForm"]["password"].value;
    if(user_login=="" || password=="")
    {
     alert("Please enter your user login and password correctly");
     return false;
    }
    return(true);
  }

 <!--
    //Form validation code will come here.
    //-->
 </script>
 </head>
 <body>
  <form action="web2.html" name="myForm" onsubmit="return(validate());">
  <h1>Login Page</h1>
  <br></br>
  User Login:<input type="text" name="user_login">
  <br></br>
  Password:<input type="password" name="password">
  <br></br>
  <input type="submit" value="LOGIN">
  </form>
  </body>
</html>


Registration form (web2.html)
<html>
 <head>
 <title>form validation</title>
 <script type="text/javascript">
  function validate()
  {
    var email=document.getElementById('email').value;
    var name=document.getElementById('name').value;
    var age=document.getElementById('age').value;
    var mob_number=document.getElementById('datetime').value;
    var datetime=document.getElementById('datetime').value;
    if(email=="" || name=="" || age=="" || mob_number=="" || datetime=="")
    {
     alert("Please enter all correct detail in the given form");
     return false;
    }
    return(true);
  }
 <!--
    //Form validation code will come here.
    //-->
 </script>
 </head>
 <body>
  <form action="submit.html" name="myForm" onsubmit="return(validate());">
  <h1>Registration Form</h1>
  <br></br>
  Name:<input type="text" name="name" id="name">
  <br></br>
  Email:<input type="text" name="email" id="email">
  <br></br>
  Mobile Number:<input type="text" name="mob_number" id="mob_number">
  <br></br>
  Age:<input type="text" name="age" id="age">
  <br></br>
  DAO:<input type="text" name="datetime" id="datetime">
  <br></br>
  Payment_option:<select name="Payment_option">
  <option value="-1" selected>[choose yours]</option>
  <option value="1">CREDIT</option>
  <option value="2">DEBIT</option>
  </select>
  <br></br>
  <input type="submit" value="SUBMIT">
  </form>
  </body>
</html>


Submit (submit.html)
<p style="color:blue; text_algin:center;font_Size:sopx">
Registered successfully.</p>











Labels:

JAVA PROGRAM TO GET DATE AND TIME USING UDP

PROGRAM:
SENDER
import java.net.*;
import java.io.*;
import java.util.*;
class UDPserver1
{
public static void main(String args[])throws Exception
{
DatagramSocket dsoc=new DatagramSocket(5217);
InetAddress host=InetAddress.getLocalHost();
String str=(new Date()).toString();
byte buf[]=str.getBytes();
dsoc.send(new DatagramPacket(buf,buf.length,host,29));
dsoc.close();
}}                                                                         



RECEIVER:
import java.net.*;
import java.io.*;
class UDPclient1
{
public static void main(String args[])throws Exception
{
DatagramSocket dsoc=new DatagramSocket(29);
byte buff[]=new byte[1024];
DatagramPacket dpack=new DatagramPacket(buff,buff.length);
dsoc.receive(dpack);
System.out.println(new String(dpack.getData()));
}
}












Labels:

WEBPAGE USING CASCADING STYLE SHEET

PROGRAM:

INLINE STYLE SHEET:
inline.html
<html>
<body>
<h1 style="color:blue;margin-left:30px;">This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>



EMBEDDED STYLE SHEET:
embedded.html
<html>
<head>
<style>
body
{
background-color linen;
}
h1{
color:red;
margin-left:40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is paragraph</p>
</body>
</html>





EXTERNAL STYLE SHEET:
external.html
<html>
<head>
<link rel="stylesheet"type="text/css"
href="mystyle.css">
</head>
<body>
<h1> This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>

mystyle .css
body{
background-color:lightblue;
}
h1{
color:navy;
margin-left:20px;
}




Labels:

CALCULATOR PROGRAM USING HTML

<html>
<head></head>
<body>
<h3>SIMPLE CALCULATOR</h3>
<br/>
<form Name="calc">
<table border= 2>
<tr>
<td colspan=4><input type=text Name="display"></td>
</tr>
<tr>
<td><input type=button value="9" OnClick="calc.display.value+='9'"></td>
<td><input type=button value="8" OnClick="calc.display.value+='8'"></td>
<td><input type=button value="7" OnClick="calc.display.value+='7'"></td>
<td><input type=button value="+" OnClick="calc.display.value+='+'"></td>
</tr>
<tr>
<td><input type=button value="6" OnClick="calc.display.value+='6'"></td>
<td><input type=button value="5" OnClick="calc.display.value+='5'"></td>
<td><input type=button value="4" OnClick="calc.display.value+='4'"></td>
<td><input type=button value="-" OnClick="calc.display.value+='-'"></td>
</tr>
<tr>
<td><input type=button value="3" OnClick="calc.display.value+='3'"></td>
<td><input type=button value="2" OnClick="calc.display.value+='2'"></td>
<td><input type=button value="1" OnClick="calc.display.value+='1'"></td>
<td><input type=button value="0" OnClick="calc.display.value+='0'"></td>
</tr>
<tr>
<td><input type=button value="*" OnClick="calc.display.value+='*'"></td>
<td><input type=button value="/" OnClick="calc.display.value+='/'"></td>
<td><input type=button value="c" OnClick="calc.display.value=''"></td>
<td><input type=button value="=" OnClick="calc.display.value=eval(calc.display.value)"></td>
</tr>
</table>
</form>
</body>

</html>

Labels: