You are on page 1of 17

161

Program 14 : Append file i.e read from 1 file and append it into another file

import java.io.*; 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) { System.out.println(e); return; } try { fout=new FileOutputStream(args[1]); } catch (Exception e) { System.out.println(e); return;

161

} } catch (Exception e) { System.out.println(e); return; }

try { do { i=fin.read(); if (i!=-1) fout.write(i); } while(i!=-1); } catch (Exception e) { System.out.println(e); return; } fin.close(); fout.close(); } }

161

Program 15: Create a applet and draw string rectangle oval with background color.

import java.awt.*; import java.applet.*; /* 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(Color.cyan); msg="inside init"; } public void start() { msg+="inside start";

161

} public void paint(Graphics g) { msg+="inside paint"; g.drawString(msg,10,30); g.fillRoundRect(70,90,140,100,30,40); g.fillOval(170,190,240,200); } } OUTPUT

161

161

Program 17: Layout Manager (Border Layout)

import java.awt.*; import java.util.*; import java.applet.*; /* 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"), BorderLayout.NORTH); add( new Label ("the footer message might go here"), BorderLayout.SOUTH); add( new Button("Right"),BorderLayout.EAST); add( new Button("left"), BorderLayout.WEST);

161

String msg=" this is sample \\n" + " just a sample string "; add( new TextArea(msg), BorderLayout.CENTER); } }

161

161

Program 16: Draw applet which display your name when clicked !

import java.awt.*; import java.awt.event.*; import java.applet.*; /* 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=me.getX(); mouseY=me.getY(); msg="Tanya";

161

repaint(); } public void mouseReleased(MouseEvent me) { mouseX=me.getX(); mouseY=me.getY(); msg="mouse released"; repaint(); } public void mouseDragged(MouseEvent me) { mouseX=me.getX(); mouseY=me.getY(); msg="*"; showStatus("Dragging mouse at " + mouseX+ ", "+ mouseY); repaint(); } public void mouseMoved(MouseEvent me) { showStatus("Moving mouse at"+me.getX()+", "+ me.getY()); } public void paint (Graphics g) { g.drawString(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\penguins.jpg" 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>

You might also like