/*BallControl.java*(控制小球的运动)*/
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class BallControl extends JPanel implements ActionListener,AdjustmentListener {
  private Ball ball=new Ball();
  private JButton jbtSuspend=new JButton("暂停");
  private JButton jbtResume=new JButton("激活");
  private JScrollBar jsbDelay=new JScrollBar();

  public BallControl() {
    JPanel panel=new JPanel();
    panel.add(jbtSuspend);
    panel.add(jbtResume);
    ball.setBorder(new javax.swing.border.LineBorder(Color.red));
    jsbDelay.setOrientation(JScrollBar.HORIZONTAL);
    ball.setDelay(jsbDelay.getMaximum());
    setLayout(new BorderLayout());
    add(jsbDelay,BorderLayout.NORTH);
    add(ball,BorderLayout.CENTER);
    add(panel,BorderLayout.SOUTH);

    jbtSuspend.addActionListener(this);
    jbtResume.addActionListener(this);
    jsbDelay.addAdjustmentListener(this);
  }

  public void actionPerformed(ActionEvent e) {
    if(e.getSource()==jbtSuspend)
      ball.suspend();
    else if(e.getSource()==jbtResume)
      ball.resume();
  }

  public void adjustmentValueChanged(AdjustmentEvent e) {
    ball.setDelay(jsbDelay.getMaximum()-e.getValue());
  }
}  
