Magazine
 
Tips ‘n’ Tricks
 

public boolean mouseDrag(Event e, int endX, int endY)
{
Graphics g = getGraphics();
// Draw a line from start point to the
end point.
g.drawLine(startX, startY, endX, endY);
// Change the start point with the end
point.
startX = endX; startY = endY;
return true;
}}

MouseScribbling.html:


<HTML>
<BODY>
<APPLET CODE=”MouseScribbling”
WIDTH=”200"
HEIGHT=”300">
</APPLET>
</BODY>
</HTML>

Compile and Run:

C:\JavaJazzup>javac MouseScribbling.
javaC:\JavaJazzup>appletviewer MouseScribbling.html

Output:

Running the applet creates an applet window like below where you can write anything by pressing and dragging the mouse. For instance, in the figure below “Java” word is written in the applet window.

 



7. Learn running external programs
(Notepad, Calculator, browser etc.) by a Java program:


Opening any sub process like Notepad, Calendar, browser etc from a java program feels good for a new java programmer. The class Runtime provides a static method getRuntime(), which helps to work with Java Runtime Environment. This is the only way to get the reference to the Runtime object. Now, by invoking its method exec(), external programs can be invoked. Here is a simple demonstration for performing this operation from a Java program.

Sept 2007 | Java Jazz Up | 72
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