-
Language
Java using Applet
-
Description
Calculates the volume of a sphere having its radius
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
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
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class VolumeOfASphere extends Applet implements ActionListener {
private static final long serialVersionUID = 1L;
private TextField field_radius;
private Label label_volume;
private Button button;
@Override
public void init() {
field_radius = new TextField(4);
label_volume = new Label();
button = new Button("Process");
setLayout(new BorderLayout());
Panel panel, subpanel;
panel = new Panel(new BorderLayout());
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(new Label("Enter the value of radius:"));
panel.add(subpanel, BorderLayout.WEST);
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(field_radius);
panel.add(subpanel);
add(panel, BorderLayout.NORTH);
panel = new Panel(new FlowLayout());
panel.add(button);
add(panel);
panel = new Panel(new BorderLayout());
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(new Label("Value of volume:"));
panel.add(subpanel, BorderLayout.WEST);
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(label_volume);
panel.add(subpanel);
add(panel, BorderLayout.SOUTH);
button.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
double radius, volume;
try {
radius = Double.parseDouble(field_radius.getText());
} catch (NumberFormatException numberFormatException) {
return;
}
volume=4.0*Math.PI*radius*radius*radius/3.0;
label_volume.setText(String.valueOf(volume));
}
}
import java.awt.*;
import java.awt.event.*;
public class VolumeOfASphere extends Applet implements ActionListener {
private static final long serialVersionUID = 1L;
private TextField field_radius;
private Label label_volume;
private Button button;
@Override
public void init() {
field_radius = new TextField(4);
label_volume = new Label();
button = new Button("Process");
setLayout(new BorderLayout());
Panel panel, subpanel;
panel = new Panel(new BorderLayout());
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(new Label("Enter the value of radius:"));
panel.add(subpanel, BorderLayout.WEST);
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(field_radius);
panel.add(subpanel);
add(panel, BorderLayout.NORTH);
panel = new Panel(new FlowLayout());
panel.add(button);
add(panel);
panel = new Panel(new BorderLayout());
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(new Label("Value of volume:"));
panel.add(subpanel, BorderLayout.WEST);
subpanel = new Panel(new GridLayout(1, 1));
subpanel.add(label_volume);
panel.add(subpanel);
add(panel, BorderLayout.SOUTH);
button.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
double radius, volume;
try {
radius = Double.parseDouble(field_radius.getText());
} catch (NumberFormatException numberFormatException) {
return;
}
volume=4.0*Math.PI*radius*radius*radius/3.0;
label_volume.setText(String.valueOf(volume));
}
}