/* * Created on Feb 13, 2005 * */ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JPanel; /** * @author knorton */ public class ControlPanel extends JPanel implements ActionListener { JButton nsp = null; JButton tsp = null; JButton bsp = null; BallPanel sim = null; public ControlPanel(BallPanel ballSim) { this.sim = ballSim; this.setPreferredSize(new Dimension(ballSim.getWidth(),50)); this.setLayout(new BoxLayout(this,BoxLayout.X_AXIS)); nsp = new JButton("No Spin"); tsp = new JButton("Top Spin"); bsp = new JButton("Back Spin"); this.add(nsp); this.add(tsp); this.add(bsp); nsp.addActionListener(this); tsp.addActionListener(this); bsp.addActionListener(this); } public void actionPerformed(ActionEvent evt) { Object s = evt.getSource(); sim.stop(); sim.resetBall(); Ball b = sim.getBall(); if (s == nsp) { b.setAngularVelocity(0f); b.setVx(20f); } else if (s == tsp) { b.setAngularVelocity(1.2f); b.setVx(20f); } else if (s == bsp) { b.setAngularVelocity(-1.2f); b.setVx(20f); } sim.start(); } }