import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import java.net.URL; import java.applet.*; public class Exercise18_22 extends JApplet { JTextField jtfSpeed = new JTextField(); JTextField jtfPrefix = new JTextField(); JTextField jtfNumOfImages = new JTextField(); JTextField jtfAudioFile = new JTextField(); JButton jbtStartAnimation = new JButton("Start Animation"); PlayImage playImage = new PlayImage(); Image[] images; AudioClip audioClip; int sleepTime; int numOfImages; // Initialize the applet public void init() { // Panel p to hold animation control JPanel p = new JPanel(); p.setLayout(new GridLayout(4, 2)); p.add(new JLabel("Animation speed in milliseconds")); p.add(jtfSpeed); p.add(new JLabel("Image file prefix")); p.add(jtfPrefix); p.add(new JLabel("Number of images")); p.add(jtfNumOfImages); p.add(new JLabel("Audio file")); p.add(jtfAudioFile); p.setBorder(new TitledBorder( "Enter information for animation")); // Panel jpButton to hold the button JPanel jpButton = new JPanel(); jpButton.setLayout(new FlowLayout(FlowLayout.RIGHT)); jpButton.add(jbtStartAnimation); // Add the button, image panel, and panel p to the applet add(jpButton, BorderLayout.NORTH); add(playImage, BorderLayout.CENTER); add(p, BorderLayout.SOUTH); // Register listener jbtStartAnimation.addActionListener(new ActionListener() { // Handle button action public void actionPerformed(ActionEvent e) { startAnimation(); } }); } public void startAnimation() { URL url = null; String prefix = jtfPrefix.getText().trim(); numOfImages = new Integer(jtfNumOfImages.getText().trim()).intValue(); String audioFile = jtfAudioFile.getText().trim(); sleepTime = new Integer(jtfSpeed.getText().trim()).intValue(); // Load the image, the image files are named // L1 - L52 in Images directory images = new Image[numOfImages]; for (int i=0; i