// File: VolumeApplet.java // // Applet to calculate sphere volumes import java.awt.*; import java.awt.event.*; public class VolumeApplet extends java.applet.Applet implements ActionListener { int radius; double volume; Label prompt1,prompt2; TextField input, output; public void init() { prompt1 = new Label("Enter the radius of a sphere: "); add(prompt1); input = new TextField(10); input.addActionListener(this); add(input); prompt2 = new Label("The volume of the sphere is: "); add(prompt2); output = new TextField(30); add(output); } public void actionPerformed (ActionEvent e) { Double vol; radius = Integer.parseInt (input.getText() ); volume = (4.0/3.0) * Math.PI * Math.pow(radius,3); vol = new Double(volume); output.setText(vol.toString()); } }