Magazine
 
Tips ‘n’ Tricks
 

out.write(buffer, 0, len);
//Writes an array of bytes to the
current
// ZIP entry data. }
out.closeEntry();
//Closes the current ZIP entry and
positions the stream
//for writing the next entry.
in.close();
}
out.close();
// Closes this output stream and
releases any system resource
//associated with the stream.
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Compile and Run:

C:\JavaJazzup>javac CreateZip.java
C:\JavaJazzup>java CreateZip
CreateZip.java CreateZip.class

Output:

Running the above program creates a zip file named “MyZippedDocuments.zip” which contains two files “CreateZip.java” and “CreateZip.class”. You can take a look below:


 

Exploring the above file shows two files inside it. You can see this in the figure below:



6. Want to scribble on the Applet window?

Do you know how to write with the mouse on the applet window? It’s an easy task. Select and save position (X and Y coordinates) of the mouse on mouse down event and position on mouse drag. Just draw a line between these two points. This process goes on until mouse is dragged. When the mouse is pressed down again the line is drawn again on the applet window.

MouseScribbling.java:

import java.awt.*;
import java.applet.*;
public class MouseScribbling extends
Applet {
// Declare variables to store mouse
point location.
int startX,startY;
// This method is called when the
user press down the mouse button.
public boolean mouseDown
(Event e, int startX, int startY)
{
// Store the point location.
this.startX = startX;
this.startY = startY;
return true;
}
// This method is called when the
user drags the pressed mouse.

Sept 2007 | Java Jazz Up | 71
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   Download PDF