161
Program 14 : Append file i.e read from 1 file and append it into another file
import [Link].*; class copyfile { public static void main (String args[]) throws Exception{ int i ; FileInputStream fin; FileOutputStream fout; try { try { fin = new FileInputStream(args[0]); } catch (Exception e) { [Link](e); return; } try { fout=new FileOutputStream(args[1]); } catch (Exception e) { [Link](e); return;
161
} } catch (Exception e) { [Link](e); return; }
try { do { i=[Link](); if (i!=-1) [Link](i); } while(i!=-1); } catch (Exception e) { [Link](e); return; } [Link](); [Link](); } }
161
Program 15: Create a applet and draw string rectangle oval with background color.
import [Link].*; import [Link].*; /* html> <head> <title>My Applet</title> </head> <Applet Code = "sample11" width="500" height="450"> </Applet> </html> */ public class sample11 extends Applet { String msg; public void init() { setBackground([Link]); msg="inside init"; } public void start() { msg+="inside start";
161
} public void paint(Graphics g) { msg+="inside paint"; [Link](msg,10,30); [Link](70,90,140,100,30,40); [Link](170,190,240,200); } } OUTPUT
161
161
Program 17: Layout Manager (Border Layout)
import [Link].*; import [Link].*; import [Link].*; /* html> <head> <title>My Applet</title> </head> <Applet Code = "sample111" width="500" height="450"> </Applet> </html> */ public class sample111 extends Applet { public void init() { setLayout (new BorderLayout()); add( new Button("this is across the top"), [Link]); add( new Label ("the footer message might go here"), [Link]); add( new Button("Right"),[Link]); add( new Button("left"), [Link]);
161
String msg=" this is sample \\n" + " just a sample string "; add( new TextArea(msg), [Link]); } }
161
161
Program 16: Draw applet which display your name when clicked !
import [Link].*; import [Link].*; import [Link].*; /* html> <head> <title>My Applet</title> </head> <Applet Code = "mouse" width="500" height="50"> </Applet> </html> */ public class mouse extends Applet implements MouseListener , MouseMotionListener { String msg=""; int mouseX=0, mouseY=0; public void init() { addMouseListener(this); addMouseMotionListener(this); }
161
public void mouseClicked(MouseEvent me) { mouseX=0; mouseY=10; msg="Amit"; repaint(); } public void mouseEntered(MouseEvent me) { mouseX=0; mouseY=10; msg="mouse entered"; repaint(); } public void mouseExited(MouseEvent me) { mouseX=0; mouseY=10; msg="mouse Exited"; repaint(); } public void mousePressed(MouseEvent me) { mouseX=[Link](); mouseY=[Link](); msg="Tanya";
161
repaint(); } public void mouseReleased(MouseEvent me) { mouseX=[Link](); mouseY=[Link](); msg="mouse released"; repaint(); } public void mouseDragged(MouseEvent me) { mouseX=[Link](); mouseY=[Link](); msg="*"; showStatus("Dragging mouse at " + mouseX+ ", "+ mouseY); repaint(); } public void mouseMoved(MouseEvent me) { showStatus("Moving mouse at"+[Link]()+", "+ [Link]()); } public void paint (Graphics g) { [Link](msg, mouseX,mouseY);
161
161
Program 18: HTML Pageusing
a) Form
<html> <body> <form> First name: <input type="text" name="firstname"><br> Last name: <input type="text" name="lastname"> </form> </body> </html>
b) Table
161
<html> <body> <table border="1"> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table> </body> </html>
c) Image
161
<html> <body> <h2>PENGUINS</h2> <img border="0" src="C:\Users\Public\Pictures\Sample Pictures\[Link]" alt="Pulpit rock" width="304" height="228"> </body> </html>
d) List
<html> <body>
161
<ul> <li>Coffee</li> <li>Milk</li> </ul> <ol> <li>Coffee</li> <li>Milk</li> </ol> </body> </html>
e) Checkbox
<html> <head> <title>My Page</title>
161
</head> <body> <form> <input type="checkbox" name="option1" value="Milk"> Milk<br> <input type="checkbox" name="option2" value="Butter" checked> Butter<br> <input type="checkbox" name="option3" value="Cheese"> Cheese<br> <br> </div> </form> </body> </html>