


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Prof. Arun Ullal at Ankit Institute of Technology and Science for Web Programming course. It includes: Combining, Java, Javascript, Calling, Routines, Controlling, Applet, HTML, Elements, Archives
Typology: Slides
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















import
java.awt.*; import
java.applet.; /**^
This
class
displays
"Hello
world!"
on
the
applet
window.
*/public
class
HelloWorld
extends
Applet
{
public
void
paint(Graphics
g)
public
void
paint(Graphics
g)
{
//^
writes
starting
at
pixel
row
15,
col
15
g.drawString("Hello
world!",
15,
15);
} }
import
java.awt.*; import
java.applet.*; import
java.util.Random; import
java.lang.Math.; /**^ This
class
can^
be^ used
to^ generate
a^ permutation
to^ be
*^ inserted
into
a^ webpage.
*/public
class
JavaPermutation
extends
Applet
{ public
String
permutation(int
n)
{ Random
r^ =^
new^ Random(); int[]
p^ =^
new^ int[n]; int^ i,
k,^ temp;
int^ i,
k,^ temp; for^ (i
=^ 0;
i^ <^
n^ ;^ i++) p[i]^
=^ i+1; double
finish
=^ Math.pow(n,3)
*^ Math.log(n)
*^ 12;
for^ (i
=^ 1;
i^ <=
finish;
i++)
{^ if
(r.nextDouble()
<^ 0.5)
{ k
=^ r.nextInt(p.length
-^ 1);
temp^
=^ p[k]; p[k]^
=^ p[k
+^ 1]; p[k+1]
=^ temp; } }
Generating
random
permutations
You^ must
use^
a^ Java-enabled
browser
to^ view
this
applet.
Here
is^ a
function
that
will
generate
random
permutations
of^ a
set^
of^ integers,
where
a^ permutation
is^ just
an^ arrangement
of^ the
integers
{1,^
2,^ ...,
n}.
Enter
a^ positive
integer
n^ (1-50):
Random
permutation
of^ {1,
...,
n}.^
import
java.awt.*; import
java.applet.*; import
java.util.Random; public
class
Monte
extends Applet
private
static
Random
randy;
private
int SIZE; private
Image
offScreenImage;
private
Graphics
offScreenGraphics;
private
int randomInRange(int
low,
int
high)
private
double
distance(int
x1,
int
y1,
int x2,
int
y2)
public
void
init()
{
randy
=^ new Random(); Dimension
dim
=^ getSize();
SIZE =
dim.width; drawCircle();
drawCircle(); } public
void
drawCircle()
BOTH getGraphics()
//^ offScreenGraphics } public
void
drawDots(int
numPoints)
numPoints
getGraphics()
offScreenGraphics } public
void
paint(Graphics
g)
g.drawImage(offScreenImage, 0,
0, null);
import
java.awt.*; import
java.applet.*; import
java.util.Random; public
class
Monte
extends Applet
public
int
numInside,
numOutside;
public
void
drawCircle()
{^
numInside
numOutside
} public
void
drawDots(int
numDots)
.^.. for (int
i^ = 0;
i^ <
numPoints;
i++) {
int^
x^ = randomInRange(0,
int^
y^ = randomInRange(0,
if^ (distance(x,
y,^
offScreenGraphics.setColor(Color.white);g.setColor(Color.white); numInside++; } else^ { offScreenGraphics.setColor(Color.black);g.setColor(Color.black); numOutside++; } }.^.. }..^