Professional Documents
Culture Documents
CONTENTS
SNo 1 2 3 4 5 6 7 8 TOPIC
Creation of Static Webpages using HTML Creation of Web Pages using CSS Programs using JavaScript Programs using VBScript Creation of Dynamic Webpages using DHTML Chat applications using Socket Programming in Java Event Driven Programs using Java Applets Programs using AWT Controls and Layouts in Java
Date
27/07/12 03/08/12 09/08/12 16/08/12 23/08/12 20/09/12 04/10/12 11/10/12
<th># of humps</th> <th>Indigenous region</th> <th>splits</th> <th>produces wool</th> </tr> <tr> <th>Camels <bactrian></th> <td>2</td> <td>Afica/Asia</td> <td rowspan =2>Llama</td> <td rowspan =2>Llama</td> </tr> <tr> <th>Llamas</th> <td>1</td> <td>Andes Mountains</td> </tr>
SAMPLE OUTPUT:
CODE:
<h1>PROFILE</h1> <ul> <li><a href=acad.html>ACADEMIC PROFILE</li> <li><a href=miniproj.html>MINI PROJECTS</li> <li><a href=personal.html>PERSONAL pROFILE</li> </ul> </center> <body> </html>
SAMPLE OUTPUT:
CODE:
<html>
<frameset cols="25%,*"> <frame src = "intro.html" name ="frame1"/> <frame name="frame2"/> </frameset> </html> intro.html <html> <body> <ul> <li><a href="rose.html" target="frame2">RoSE</a></li> <li><a href="jasmine.html" target="frame2">JasminE</a></li> <li><a href="lotus.html" target="frame2">LoTus</a></li> </ul>
SAMPLE OUTPUT:
CODE:
<html> <body> <img src="camel" usemap="#mymap" /> <map name="mymap" id="mymap"> <area shape="circle" coords="10,10,50" href="q1.html" /> <area shape ="circle" coords="40,40,100" href="1b.html"/> </map> </body> </html>
SAMPLE OUTPUT:
<html> <head> <style type="text/css"> ul{margin-left:75} .nested{margin-left:15} em{color:red;} a{color:blue;text-decoration:none} a:hover{text-decoration:underline;color:red;background-color:aqua;} </style> </head> <body> <ul> <li>Milk</li> <li>Bread</li> <ul class="nested">
<li>White bread</li> <li>Rye Bread</li> <li>Whole wheat bread</li> </ul> <li>Rice</li> <li>Potatoes</li> <li>Pizza <em>with mushroom</em></li>
</ul> <br/><br/> <center><a href=" ">Go to the grocery store</a></center> </body> </html>
SAMPLE OUTPUT:
CODE:
<html> <head>
<li>White bread</li> <li>Rye Bread</li> <li>Whole wheat bread</li> </ul> <li>Rice</li> <li>Potatoes</li> <li>Pizza <em>with mushroom</em></li> </ul> <br/><br/> <center><a href=" ">Go to the grocery store</a></center> </body> </html>
c22.css
SAMPLE OUTPUT:
CODE:
<html> <body> <p><center> Thanks for visiting my web site. I hope you enjoy a lot. Please Note: This site will be moving soon. Check periodically for updates. </p></center>
</body> </html>
SAMPLE OUTPUT:
CODE:
<html>
<body> <input type="radio" name="color" value="Red" CHECKED >RED</input><br/> <input type="radio" name="color" value="Blue" >BLUE</input><br/> <input type="radio" name="color" value="yellow" >Yellow</input><br/> <input type="radio" name="color" value="Green" >Green</input><br/> <input type="submit"value="SUBMIT" action="reset"></input><br/><br/> </body> <table> <tr> <td style="background-color:red;color=black;">RED---25%</td> </tr> <tr> <td style="background-color:blue;color=black;">BLUE--15%</td> </tr> <tr> <td style="background-color:yellow;color=black;">YELLOW--20%</td> </tr> <tr>
</html>
SAMPLE OUTPUT:
CODE:
<html> <head> <style type="text/css"> h1{padding:0.5em;border:groove;margin:0.5em;} .greenMove{color:green;margin-top:25;margin-left:15} </style> </head> <body> <h1> This is of type h1</h1> <h1 class="greenMove"> this para follows a style of class greenMove</h1> </body> </html>
SAMPLE OUTPUT:
</head> <body>
<input type="text" id="num" /> <input type="submit" value="calc" id="cal" onclick="func()"/> <script type="text/javascript"> function func() { var x=document.getElementById("num").value;
towers('1','3','2',document.getElementById("num").value);
} function towers(i,f,m,num) { num=+num; if(num===1) { document.write("move disk "+ num +" from "+ i +" to "+ f +"<br/>");}
else { towers(i,m,f,num-1); document.write("move disk "+ num +" from "+ i +" to "+ f +"<br/>"); towers(m,f,i,num-1); } } </script> </body> </html>
Sample Output:
CODE:
<html> <head> <title> perfect number </title> <script type="text/javascript"> function perfect(num) { /*num=+num;*/ var temp=0; var i=1; while(i<=(num/2)) { if(num%i==0)
Sample Output:
CODE:
<html> <head> <script type="text/javascript"> function getInput() { var x = document.getElementById("aid").value.toString(); var xlength = x.length;
else { document.write("No!"); } } </script> </head> <body> <input type="text" id="aid" /> <input type="submit" value="accept" id="acc" onclick="getInput()" /> </body> </html>
Sample output:
CODE:
<html> <head> <script type="text/javascript"> function sort(arr) { var i=0,j; var n=arr.length; while(i<n) { j=0; while(j<(n-i+1)) { if(arr[j]>arr[j+1]) { var temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } j++; }i++; }
Sample Output:
ci=ci;
} </script> </head>
<body> <p>Principle :-
Rate
:-
<input type="text" name="rate" id="rate"/> <br/> <input type="submit" onclick="compound()" value="calculate" /> </body> </html>
Sample Output:
CODE:
<html> <head> <title> Upper Lower Case </title> <script type="text/javascript"> function upperlower() { var string=str.value; document.write("first "+string.toLowerCase()+"<br/>"); document.write("second "+string.toUpperCase()+<br/>);
</script> <body>
<form id="upperlower" method="post"> <label>String</label> <input type="text" id="str" name="str" /> <input type="submit" value="accept" onclick="upperlower()" /> </form>
</body> </html>
Sample Output:
Code:
<html>
document.getElementById("result").innerHTML=a.join(" "); }
</script>
</head> <body> <label>Enter:</label> <input type="text" id="str" name="str" /> <input type="button" value="accept" id="tok" onclick="tokenize()" />
Sample output:
Code:
<html> <head> <script type="text/javascript"> function linearsearch() {
var p=str.value; var key=parseInt(red.value); if(!p || !key) { alert("ERROR"); } var a=p.split(" "); var i=0; while(i< a.length) { if(a[i]==key)
break; i++; } if(i< a.length) { document.getElementById("result").innerHTML="found at position "+i+"<br/>" } else { document.getElementById("result").innerHTML="NOT found "+"<br/>" } }
</script>
<body> <label>Enter the numbers: </label> <input type="text" id="str" name="str"/> <br/> <label>key: </label> <input type="text" id="red" name="red"/> <br/> <input type="button" id="s" value="search" onclick="linearsearch()"/> <br/> <div id="result" /> </body> </html>
Sample Output:
Code:
<html> <head> <title> Your Best Website </title> </head> <body>
Select your favorite website: <select id='menu'> <option id='wikipedia'>Wikipedia</option> <option id='facebook'>Facebook</option> <option id='google'>Google</option> <option id='yahoo'>Yahoo!</option> <option id='reddit'>redddit</option> <option id='tumblr'>tumblr</option> </select>
<div id="result"></div>
document.getElementById('result').innerHTML = 'You chose ' + chosenItem.value; e.preventDefault(); return false; } </script> </body> </html>
Sample Output:
</script> </head> <body onLoad="moveDown('myObject');"> <div id="myObject" style="position: absolute; left: 50px; top: 50px; height: 50px; width: 50px; background-color: #cccccc;"></div>
</body> </html>
Sample Output:
Code:
<html> <head> <title>Calculator</title>
</head> <body> <input type="text" id="scr" size=20 /></br> <input type="button" value="1" id="num1" onclick="func(this.value)" /> <input type="button" value="2" id="num2" onclick="func(this.value)" /> <input type="button" value="3" id="num3" onclick="func(this.value)" /> <input type="button" value="%" id="op%" onclick="ops(this.value)" /> </br> <input type="button" value="4" id="num4" onclick="func(this.value)" /> <input type="button" value="5" id="num5" onclick="func(this.value)" /> <input type="button" value="6" id="num6" onclick="func(this.value)" /> <input type="button" value="*" id="op*" onclick="ops(this.value)" /> </br> <input type="button" value="7" id="num7" onclick="func(this.value)" /> <input type="button" value="8" id="num8" onclick="func(this.value)" /> <input type="button" value="9" id="num9" onclick="func(this.value)" /> <input type="button" value="/" id="op/" onclick="ops(this.value)" /> </br> <input type="button" value="0" id="num0" onclick="func(this.value)" /> <input type="button" value="+" id="op+" onclick="ops(this.value)" /> <input type="button" value="-" id="op-" onclick="ops(this.value)" /> <input type="button" value="=" id="op=" onclick="equalto()" />
</br> <input type="button" value="sin" id="sin" onclick="trig(this.value)" /> <input type="button" value="cos" id="cos" onclick="trig(this.value)" /> <input type="button" value="tan" id="tan" onclick="trig(this.value)" /> </br> <input type="button" value="CE"id="num0" onclick="ce()" />
<script type="text/javascript"> var a,b; var op; var clearflag=0; var res; function ce() { document.getElementById("scr").value=""; } function trig(value) { a=parseInt(document.getElementById("scr").value); var str=value;
} function func(value) { if(clearflag==1) { document.getElementById("scr").value=""; clearflag=0; } document.getElementById("scr").value+=value; } function ops(value) { a=parseInt(document.getElementById("scr").value); clearflag=1;
switch(value) { case '+' : op= '+'; break; case '-' : op= '-'; break;
break;
case '%' : op= '%'; break; } } function equalto() { b=parseInt(document.getElementById("scr").value); var num; switch(op) { case '+' : num = a + b; break; case '-' : num= a - b; break;
Sample Output:
Code:
<html> <head><title></title> <script type="text/javascript"> function hello() { var name1=document.getElementById("name1").value; if(name1=="" ) { alert("enter valid name"); } var flag=1; for(i=0;i<name1.length;i++) { if((name1[i]>='A' && name1[i]<='Z') || (name1[i]>='a' && name1[i]<='z')); else { flag=0; break; } } if(flag==0) { alert("Invalid name"); }
{ alert("enter correct age"); } var phno=document.getElementById("phno").value; var count=0; flag=0; for(i=0;i<phno.length;i++) { if(phno[i]>='0' && phno[i]<='9') { count++; } else if(phno[i]==' ' && flag==0) { if(count==3 || count==4) { count=0; flag=1; } else { alert("Invalid std code is 3 to 4"); break; } } else { alert("invalid phone number"); break;
} } if(count!=6 && count!=8) alert("phone number only between 6 to 8"); var email=document.getElementById("email").value; flag=0; i=0;
while(email[i]!='@' && i!=email.length-1) { if((email[i]>='A' && email[i]<='Z') || (email[i]>='a' && email[i]<='z')); else {
i++; } if(i==email.length-1) { alert("invalid email id"); return; } i++; while(email[i]!='.' && i!=email.length-1 ) {
if((email[i]>='A' && email[i]<='Z') || (email[i]>='a' && email[i]<='z')); else { alert("invalid email id . "); return; } i++; } if(i==email.length-1) { alert("invalid email id"); return; } i++; while(i!=email.length-1) { if((email[i]>='A' && email[i]<='Z') || (email[i]>='a' && email[i]<='z')); else {
<form> Name: <input type=text id="name1" /><br /> Age: <input type=text id="age" /><br /> Address: <input type=text id="address" /><br /> Sex: <input type=text id="sex" /><br /> Hobbies: <input type=text id="hobbies" /><br /> Phone Number: <input type=text id="phno" /><br /> E-mail ID: <input type=text id="email" /><br /> <input type="submit" value="Submit" onclick="hello()" />
Sample Output:
Code:
<html> <head> <script language="JavaScript"> function change(objectID){ var thisObj = document.getElementById(objectID); thisObj.rows[0].cells[0].innerHTML="Thanks" } </script> </head> <body> <table id="table1"> <tr> <td>Welcome</td> </tr> <tr> <td><input type="button" name="OK" value="OK" onClick="change('table1');"></td> </tr> </table> </body> </html>
Sample Output:
Chat Applications using Socket Programming in Java Ex. No: 6 Date : 20/09/12
PROBLEM STATEMENT Create a Chat application using socket programming in Java CODE: 1. Chat application using TCP Server.java import java.io.*; import java.net.*; public class Server{ static static static SocketclientSocket = null; ServerSocketserverSocket = null; clientThread t[] = new clientThread[10];
public static void main(String args[]) { intport_number=2222; System.out.println("Usage: java MultiThreadChatServer \n"+"Now using port number="+port_nu mber); try{ serverSocket = new ServerSocket(port_number); catch (IOException e){ System.out.prin tln(e); } while(true){ try { clientSocket = serverSocket.accept(); for(int i=0; i<=9; i++){ if(t[i]==null) { (t[i] = new clientThread(clientSocket,t)).start(); break; } } }
catch (IOException e) {
System.out.println(e);} } } classclientThread extends Thread { DataInputStream is = null; PrintStreamos = null; Socket clientSocket = null; clientThread t[]; publicclientThread(Socket clientSocket, clientThread[] t){ this.clientSocket=clientSocket; this.t=t; } public void run() { String line; String name; try{ is = new DataInputStream(clientSocket.getInputSt ream()); os = new PrintStream(clientSocket.getOutputStrea m()); os.println("Enter your name."); name = is.readLine(); while (true) { line = is.readLine(); if(line.startsWit h("1")) break; for(int i=0; i<=9; i++) if (t[i]!=null) t[i].os.println(name+": "+line); } for(int i=0; i<=9; i++) if (t[i]!=null && t[i]!=this) t[i].os.println(" The user "+name+" is leaving the chat room !!! " ); os.println(" Bye "+name); for(int i=0; i<=9; i++) if (t[i]==this) t[i]=null; is.close(); os.close(); clientSocket.c lose(); } catch(IOException e){};}} }
Client.java import java.io.*; import java.net.*; public class Client implements Runnable{ static Socket clientSocket = null; staticPrintStreamos = null; staticDataInputStream is = null; staticBufferedReaderinput Line = null; staticboolean closed = false; public static void main(String[] args) { intport_number=2222;// The default port String host="localhost"; if (args.length< 2){ System.out.println("Usage: java MultiThreadChatClient \n"+ "Now using host="+host+",port_number="+port_number); } else host=args[0]; { port_number=Integer.valueOf(args[1]).intValue(); } try { clientSocket = new Socket(host, port_number); inputLine = new BufferedReader(new InputStreamReader(System.in)); os = new PrintStream(clientSocket.getOutputStream()); is = new DataInputStream(clientSocket.getInputStream());
catch (UnknownHostException e) { System.err.println("Don't know about host "+host); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to the host "+host); } try { catch (IOException e) { System.err.println("IOExcep tion: } SAMPLE OUTPUT: Start the Server.java program C:\Program
" + e);
Files\Java\jdk1.5.0_06\bin>javac Server.java C:\Program Files\Java\jdk1.5.0_06\bin>java Server Usage: java MultiThreadChatServer Now using port number=2222 Start the Client.java program for client1 C:\Program Files\Java\jdk1.5.0_06\bin>javac MultiThreadChatClient.java -Xlint C:\Program Files\Java\jdk1.5.0_06\bin>java MultiThreadChatClient Usage: java MultiThreadChatClient Now using host=localhost, port_number=2222 Enter your name. abc Welcome abc xyz: hi hi abc: hi Start the Client.java program for client2 C:\Program Files\Java\jdk1.5.0_06\bin>javac MultiThreadChatClient.java -Xlint C:\Program Files\Java\jdk1.5.0_06\bin>java MultiThreadChatClient Usage: java MultiThreadChatClient Now using host=localhost, port_number=2222 Enter your name. xyz Welcome xyz hi
try { ioSocket = new DatagramSocket(ioPort); } catch (Exception e) { ioPort = 222; receiverPort = 111; ioSocket = new DatagramSocket(ioPort); } System.out.println("chat on port " + ioPort + ""); new receiver(ioSocket); // Start receiver thread while ((userIn=in.readLine())!=null) { sendBuffer = userIn.getBytes(); sendPacket = new DatagramPacket( sendBuffer, sendBuffer.length, InetAddress.getByName(toName), receiverPort); ioSocket.send(sendPacket); // Send datagram } System.exit(0); // Exit, stopping receiver } } class receiver implements Runnable { DatagramSocketioSocket; receiver(DatagramSocketio Socket) { this.ioSocket = ioSocket; new Thread(this).start();// Start thread at run() } public void run() { bytereceiveBuffer[] = new byte[128]; DatagramPacketreceivePacket = new DatagramPacket(receiveBuffer, 128); while(true) { try { ioSocket.receive(receivePacket); }// Wait for datagram catch (Exception e) {} System.out.println( new String(receivePacket.getData(), 0, receivePacket.getLength())); } }
} SAMPLE OUTPUT: Start the Chat.java program for client1 C:\Program Files\Java\jdk1.5.0_06\bin>javac chat.java -Xlint C:\Program Files\Java\jdk1.5.0_06\bin>java chat Hi Rec : Hello Start the Chat.java program for client2 C:\Program Files\Java\jdk1.5.0_06\bin>javac chat.java -Xlint C:\Program Files\Java\jdk1.5.0_06\bin>java chat
Rec: Hi hello RESULT:Two way TCP / IP and UDP chat application is done using Java.
Event Driven Programs using Java Applets Ex. No: 7 Date : 04/10/12
PROBLEM STATEMENT Create a Event Driven Programs using Java Applets CODE:
import java.applet.Applet; import java.awt.*;
public class pga extends Applet{ String temp; public void init(){ } public void paint (Graphics g) { int num=5; g.drawString("Displayed string",10,10); g.drawLine(55,55,32,32); g.drawOval(200,50,50,50); g.fillOval(70,100,40,40); g.drawOval(10,30,20,40); g.fillOval(100,150,30,40); g.drawRect(170,170,40,15); g.fillRect(120,21,70,15); g.drawArc(50,50,70,70,0,75); g.fillArc(175,30,30,50,0,90);
Sample output:
Code:
import java.applet.Applet; import java.awt.*;
public class pgb extends Applet { String s; public void init(){ } public void start(){
g.drawString("font families:", 10, 20); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontList[] = ge.getAvailableFontFamilyNames(); for(int i=0;i<fontList.length;i++) g.drawString(fontList[i],10,30 + 10*i); }}
Sample Output:
Code:
import java.applet.Applet; import java.awt.*; public class pgc extends Applet { String S; public void init() { setBackground(Color.CYAN); setForeground(Color.BLUE); } public void start() { S="Applet STARTS"; } @Override public void paint(Graphics g) { g.drawString(S,50,20); showStatus("STATUS MESSAGE"); } }
Sample Output:
Code:
import java.applet.Applet; import java.awt.*; import java.net.*; import java.util.*;
public void paint(Graphics g) { u1=getCodeBase(); s1="code base:"+u1.toString(); g.drawString(s1,10,20); u2=getDocumentBase(); s2="doc base:"+u2.toString(); g.drawString(s2,10,60); }
Sample Output:
Result: Event Driven Programs using Java Applets were created successfully.
Programs using AWT Controls and Layouts in Java Ex. No: 8 Date : 11/10/12
public class QuestionA implements ActionListener { private JFrame frame; private JButton buttonYes; private JButton buttonNo; private JLabel label; private JPanel panel;
frame.setVisible(true); }
Sample Output:
Code:
import java.awt.GridLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel;
public class QuestionB implements ItemListener { private JFrame frame; private JCheckBox[] checkbox = new JCheckBox[4]; private JLabel[] label = new JLabel[4]; private JPanel panel; private String[] str = {"WINDOWS 98","WINDOWS NT","SOLARIS","MACOS"};
int i; for(i=0;i<4;i++) { checkbox[i] = new JCheckBox(str[i]); if(i==0) { checkbox[i].setSelected(true); } checkbox[i].addItemListener(this); label[i] = new JLabel(); }
if(checkbox[i].isSelected()) { label[i].setText("Selected"); }
else {
label[i].setText("Not Selected"); } }
frame.setVisible(true); }
public void itemStateChanged(ItemEvent ie) { JCheckBox tempCheckBox = (JCheckBox)ie.getSource(); String lbl = tempCheckBox.getText();
if(tempCheckBox.isSelected()) {
label[index].setText("Selected"); }
Sample Output:
Code:
import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.GridLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel;
public class QuestionC implements ItemListener { private JFrame frame; private CheckboxGroup cbg = new CheckboxGroup(); private Checkbox[] checkbox = new Checkbox[4]; private JLabel[] label = new JLabel[4]; private JPanel panel; private String[] str = {"WINDOWS 98","WINDOWS NT","SOLARIS","MACOS"};
panel.setLayout(new GridLayout(4,2));
int i; for(i=0;i<4;i++) { if(i==0) { checkbox[i] = new Checkbox(str[i], cbg, true); } else { checkbox[i] = new Checkbox(str[i], cbg, false); } checkbox[i].addItemListener(this); label[i] = new JLabel(); }
if(checkbox[i].getState()) {
frame.setVisible(true); }
public void itemStateChanged(ItemEvent ie) { Checkbox tempCheckBox = (Checkbox)ie.getSource(); String lbl = tempCheckBox.getLabel();
Sample Output:
Code:
import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.ScrollPaneConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener;
public class QuestionD implements ListSelectionListener { private String[] list_os_entries = {"WINDOWS 98","WINDOWS NT","LINUX","SOLARIS","MACOS"}; private String[] list_browser_entries = {"IE","NETSCAPE","LYNX","FIREFOX","OPERA"}; private JList os_list; private JList browser_list; private JFrame frame; private JPanel panel; private JLabel label;
frame.setSize(400,400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
scroller1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scroller2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
public void valueChanged(ListSelectionEvent lse) { if(!lse.getValueIsAdjusting()) { String os = (String)os_list.getSelectedValue(); String browser = (String)browser_list.getSelectedValue(); label.setText("Message: "+browser+" open in "+os+" OS"); } }
Sample Output:
Code:
public class QuestionE implements ActionListener { private JFrame frame; private JPanel panel; private JButton[] button = new JButton[16];
int i; for(i=1;i<=16;i++)
frame.getContentPane().add(panel); frame.setVisible(true); }
public void actionPerformed(ActionEvent ae) { JButton tempButton = (JButton)ae.getSource(); JOptionPane.showMessageDialog(frame, "Button "+tempButton.getText()+" was clicked!!"); }
Sample Output:
Result: Programs using AWT Controls and Layouts in Java were created successfully.