/
applets.tex
50 lines (43 loc) · 1023 Bytes
/
applets.tex
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
\pagebreak{}
\section{Applets}
\begin{verbatim}
import java.awt.*;
import java.applet.*;
public class Sum extends Applet {
TextField text1,text2;
public void init()
{
text1 = new TextField(8);
text2 = new TextField(8);
add(text1);
add(text2);
text1.setText("");
text2.setText("");
}
public void paint(Graphics g)
{
int x = 0, y = 0, z = 0;
String s1,s2,s;
g.drawString("Input a number in the textbox", 10, 50);
try {
s1 = text1.getText();
x = Integer.parseInt(s1);
s2 = text2.getText();
y = Integer.parseInt(s2);
}
catch (Exception ex) {
}
z = x + y;
s = String.valueOf(z);
g.drawString("The sum is:", 10, 75);
g.drawString(s, 100, 75);
}
public boolean action(Event event, Object object)
{
repaint();
return true;
}
}
\end{verbatim}
\section*{Output}
\includegraphics{applet}