Skip to content

Commit b68f7d6

Browse files
committed
Added basic programs of JavaApplets
1 parent bd1743c commit b68f7d6

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

JavaApplets/FirstApplet.htm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<title>First Applet</title>
4+
</head>
5+
<body>
6+
<applet code = "FirstApplet.class" height = "69" width = "420">
7+
<!-- <b>ERROR!!<br>You must use java enabled browser</b> -->
8+
</applet>
9+
</body>
10+
</html>

JavaApplets/FirstApplet.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
<applet
3+
code = "FirstApplet.class"
4+
width = "420"
5+
height = "420"
6+
7+
alt = "Applet Here"
8+
name = "FirstApplet"
9+
align = "center"
10+
>
11+
<!--PARAMs to pass-->
12+
</applet>
13+
*/
14+
15+
import java.applet.Applet;
16+
import java.awt.*;
17+
18+
public class FirstApplet extends Applet{
19+
// public void init(){}
20+
public void paint(Graphics g) {
21+
g.drawString("Hello World", 10, 10);
22+
}
23+
}
24+
25+
// code: Name of applet class file.
26+
// width: Width of applet.
27+
// height: Height of applet.
28+
// codebase: Directory path for applet code eg:'/Applets'.
29+
// alt: Text to show if applet failed to load.
30+
// name: Name of applet.
31+
// align: Setting alignment of the applet.

JavaApplets/GraphicsMethods.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// <applet
2+
// code = "GraphicsMethods.class"
3+
// width = "420"
4+
// height = "420"
5+
// alt = "Applet Here"
6+
// name = "GraphicsMethods"
7+
// align = "center"
8+
// >
9+
// </applet>
10+
11+
import java.applet.Applet;
12+
import java.awt.*;
13+
14+
public class GraphicsMethods extends Applet{
15+
public void paint(Graphics g) {
16+
17+
// int getWidth();
18+
int w = getWidth();
19+
// int getHeight();
20+
int h = getHeight();
21+
// Dimension getSize();
22+
Dimension d = getSize();
23+
double wD = d.getWidth();
24+
double hD = d.getHeight();
25+
26+
if(w == wD && h == hD) {
27+
// void drawString("Message", x, y);
28+
g.drawString("(" + w + ", " + h + ")", 10, 10);
29+
}
30+
31+
Font f = new Font("Arial", Font.PLAIN, 28);
32+
// void setFont(Font f);
33+
g.setFont(f);
34+
35+
// void setBackground(Color c);
36+
setBackground(Color.WHITE);
37+
38+
// Color c = new Color(78, 32, 91);
39+
// void setForeground(Color c);
40+
setForeground(new Color(78, 32, 91)); // Anonymous Object
41+
42+
// void drawLine(int x1, int y1, int x2, int y2);
43+
g.drawLine(10, 50, 100, 50);
44+
45+
// void drawRect(int x, int y, int width, int height);
46+
g.drawRect(10, 100, 100, 70);
47+
48+
// void fillRect(int x, int y, int width, int height);
49+
g.fillRect(150, 100, 100, 70);
50+
51+
// void draw3DRect(int x, int y, int width, int height, boolean raised);
52+
g.draw3DRect(10, 200, 100, 70, true);
53+
54+
// void fill3DRect(int x, int y, int width, int height, boolean raised);
55+
g.fill3DRect(150, 200, 100, 70, true);
56+
57+
// void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);
58+
g.drawRoundRect(10, 300, 100, 70, 25, 25);
59+
60+
// void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);
61+
g.fillRoundRect(150, 300, 100, 70, 25, 25);
62+
63+
// void drawOval(int x, int y, int xDia, int yDia);
64+
g.drawOval(10, 400, 100, 70);
65+
66+
// void fillOval(int x, int y, int xDia, int yDia);
67+
g.fillOval(150, 400, 100, 70);
68+
69+
// void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle);
70+
g.drawArc(150, 50, 100, 100, 45, 90);
71+
72+
int x1[] = {10, 30, 60, 90, 100, 150};
73+
int y1[] = {500, 520, 500, 530, 500, 520};
74+
// void drawPolyLine(int[] x, int[] y, int numSides);
75+
g.drawPolyline(x1, y1, 5);
76+
77+
int x2[] = {150, 170, 200, 230, 240, 290};
78+
int y2[] = {500, 520, 500, 530, 520, 520};
79+
// void drawPolygon(int[] x, int[] y, int numSides);
80+
g.drawPolygon(x2, y2, 5);
81+
}
82+
}

JavaApplets/test.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<applet
2+
code = "GraphicsMethods.class"
3+
width = "1000"
4+
height = "1000"
5+
alt = "Applet Here"
6+
name = "Methods"
7+
align = "center"
8+
>
9+
</applet>
10+
11+
<!--This Workd Too!!-->

0 commit comments

Comments
 (0)