Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
43 lines (41 loc) · 931 Bytes

File metadata and controls

43 lines (41 loc) · 931 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package chapter17;
/* J17_04.java */
/* An Applet that takes input from keyboard*/
import java.awt.*;
import java.applet.*;
public class J17_04 extends Applet
{
TextField Text1, Text2;
public void init ()
{
Text1 = new TextField(10); // 10 as text length
Text2 = new TextField(10); //
add(Text1);
add(Text2);
Text1.setText(""); // initial text
Text2.setText("");
}
public void paint (Graphics g)
{
int x=0, y=0, z=0;
String S1, S2, S3;
g.drawString("Input a number in each box and press ENTER to sum:", 10,60);
try
{
S1 = Text1.getText();
x = Integer.parseInt(S1);
S2 = Text2.getText();
y = Integer.parseInt(S2);
}
catch (Exception e){ }
z = x + y;
S3 = String.valueOf(z);
g.drawString("Sum is: ", 10,80);
g.drawString(S3,80,80);
}
public boolean action(Event event, Object Obj)
{
repaint();
return true;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.