Java Reference
In-Depth Information
Ellipse2D fBall;
/** Reset parameters for a new drop. **/
void reset () {
fFrameHt = getHeight ();
fFrameWd = getWidth ();
fXPixel = getWidth ()/2;
fY = fY0; fVy = 0.0;
// Conversion factor from cm to pixels
// Start the ball about 20% from the top.
fYConvert = fFrameHt / (1.2 * fY0);
// Choose a size for the ball relative
// to height of drawing area.
fRadius = (int) ((0.1 * fY0) * fYConvert);
fDiam = 2*fRadius;
// Make the ball
fBall = new Ellipse2D.Double(fXPixel-fRadius,
fYPixel-fRadius,
fDiam, fDiam);
setBackground (Color.WHITE);
fDropDone = false;
} // reset
/** Draw the ball at its current position. **/
public void paintComponent (Graphics g) {
super.paintComponent (g);
Graphics2D g2 = (Graphics2D)g;
// Antialiasing for smooth surfaces.
g2.setRenderingHint(RenderingHints.KEY - ANTIALIASING,
RenderingHints.VALUE - ANTIALIAS - ON);
// Determine position after this time increement
calcPosition ();
// Move the ball.
fBall.setFrame(fXPixel-fRadius, fYPixel-fRadius,
fDiam,fDiam);
// Want a solid red ball.
g.setColor (Color.RED);
g2.fill(fBall);
// Now draw the ball
g2.draw (fBall);
 
Search WWH ::




Custom Search