//dhaval adjoadh dhaval@mit.edu Section 12 Pierre Ghisbain import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.*; import javax.swing.*; public class ball extends JPanel implements ActionListener { private double x = 0.0; private double y = 260.0; private double xvel = 5.0; private double yvel = -30; private int tx, ty = 0; private Timer timer; public static void main( String[] args ) { JFrame frame = new JFrame( "Ball drop" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.getContentPane().add( new ball(), "Center" ); frame.setSize( 700, 300 ); frame.setVisible( true ); } public ball() { setBackground( Color.black ); timer = new Timer(100, this); timer.start(); } public void actionPerformed(ActionEvent e){ repaint(); tx = tx + 1; ty = ty + 1; if (y >= 261.0){ ty = 0; yvel += 5.0; } } public void paintComponent( Graphics g ) { super.paintComponent( g ); Graphics2D g2 = (Graphics2D) g; Shape Ellipse = new Ellipse2D.Double(x, y, 10.0, 10.0); g2.setPaint(Color.white); g2.fill(Ellipse); GeneralPath path = new GeneralPath(); g2.setPaint(Color.blue); g2.setStroke(new BasicStroke(8)); path.moveTo(0,260); x = xvel*tx; y = 260 + yvel*ty + 1*ty*ty; // path.lineTo(x,y); // g2.draw(path); } }