Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
bouncing-ball/BallPanel.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
32 lines (29 sloc)
1.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Lab 7 Task 1: BlockPanel.java | |
* Creates the panel to be placed inside the BouncingSquareApp window. | |
*/ | |
public class BallPanel extends javax.swing.JPanel { | |
// Declare component objects | |
private BouncingBall _ball1; | |
private BouncingBall _ball2; | |
public BallPanel () { | |
// Instantiate the JPanel | |
super(); | |
// Set the background to black | |
this.setBackground(java.awt.Color.BLACK); | |
// Instantiate the bouncing blocks | |
_ball1 = new BouncingBall (new java.awt.Color(255,64,64), 10, this); | |
_ball2 = new BouncingBall (java.awt.Color.WHITE, 5, this); | |
// Set the initial location and size of the block | |
_ball1.setLocation(25, 35); | |
_ball1.setSize(10, 10); | |
_ball2.setLocation(150, 25); | |
_ball2.setSize(10, 10); | |
} | |
public void paintComponent (java.awt.Graphics aBrush) { | |
super.paintComponent(aBrush); | |
java.awt.Graphics2D betterBrush = (java.awt.Graphics2D) aBrush; | |
_ball1.fill(betterBrush); | |
_ball2.fill(betterBrush); | |
} | |
} |