balloons
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| balloons [2018/08/17 08:35] – frchris | balloons [2024/08/25 16:53] (current) – frchris | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | [[https:// | ||
| + | |||
| CheckList: | CheckList: | ||
| - Add a method in the '' | - Add a method in the '' | ||
| Line 5: | Line 7: | ||
| - Change '' | - Change '' | ||
| - Change '' | - Change '' | ||
| - | - Change '' | + | - Change '' |
| - Modify the '' | - Modify the '' | ||
| Challenges: | Challenges: | ||
| Line 12: | Line 14: | ||
| - Instead of '' | - Instead of '' | ||
| - | <code java Balloon.java> | + | <file java Balloon.java> |
| import java.awt.Color; | import java.awt.Color; | ||
| import java.awt.Graphics; | import java.awt.Graphics; | ||
| Line 47: | Line 49: | ||
| } | } | ||
| - | </code> | + | </file> |
| <code java BalloonDrop.java> | <code java BalloonDrop.java> | ||
| + | import java.awt.Color; | ||
| import java.awt.Font; | import java.awt.Font; | ||
| import java.awt.Graphics; | import java.awt.Graphics; | ||
| Line 58: | Line 61: | ||
| import java.awt.event.KeyListener; | import java.awt.event.KeyListener; | ||
| import java.util.ArrayList; | import java.util.ArrayList; | ||
| + | |||
| import javax.swing.JFrame; | import javax.swing.JFrame; | ||
| import javax.swing.JPanel; | import javax.swing.JPanel; | ||
| import javax.swing.Timer; | import javax.swing.Timer; | ||
| + | |||
| public class BalloonFall extends JPanel implements KeyListener, | public class BalloonFall extends JPanel implements KeyListener, | ||
| { | { | ||
| Line 68: | Line 71: | ||
| public static int HEIGHT=600; | public static int HEIGHT=600; | ||
| private Font titleFont, regularFont; | private Font titleFont, regularFont; | ||
| - | private ArrayList<Balloon& | + | private ArrayList<Balloon> balloons; |
| private Timer timer; | private Timer timer; | ||
| /** | /** | ||
| Line 82: | Line 85: | ||
| titleFont = new Font(" | titleFont = new Font(" | ||
| regularFont = new Font(" | regularFont = new Font(" | ||
| - | balloons = new ArrayList<Balloon>(); | + | balloons = new ArrayList<Balloon>(); |
| timer = new Timer(10, this); | timer = new Timer(10, this); | ||
| timer.start(); | timer.start(); | ||
| Line 99: | Line 102: | ||
| window.addKeyListener(app); | window.addKeyListener(app); | ||
| window.setVisible(true); | window.setVisible(true); | ||
| + | |||
| } | } | ||
| + | |||
| /** | /** | ||
| * This is the method to change what is drawn to the screen: | * This is the method to change what is drawn to the screen: | ||
| Line 119: | Line 122: | ||
| x.draw(g); | x.draw(g); | ||
| } | } | ||
| + | |||
| } | } | ||
| + | |||
| /** | /** | ||
| * These 3 methods need to be declared to implement the KeyListener Interface | * These 3 methods need to be declared to implement the KeyListener Interface | ||
| Line 128: | Line 131: | ||
| @Override | @Override | ||
| public void keyTyped(KeyEvent e) {} | public void keyTyped(KeyEvent e) {} | ||
| + | |||
| @Override | @Override | ||
| public void keyPressed(KeyEvent e) {} | public void keyPressed(KeyEvent e) {} | ||
| + | |||
| @Override | @Override | ||
| public void keyReleased(KeyEvent e) { | public void keyReleased(KeyEvent e) { | ||
| + | |||
| int size = Balloon.randomInt(50, | int size = Balloon.randomInt(50, | ||
| int x = Balloon.randomInt(0, | int x = Balloon.randomInt(0, | ||
| Line 141: | Line 144: | ||
| repaint(); | repaint(); | ||
| } | } | ||
| - | + | ||
| @Override | @Override | ||
| /** | /** | ||
| Line 152: | Line 155: | ||
| while ( i < balloons.size() ) { | while ( i < balloons.size() ) { | ||
| balloons.get(i).drop(); | balloons.get(i).drop(); | ||
| - | // if ( balloons . get ( i ) . getBottom ( ) > HEIGHT | + | // |
| - | if ( balloons.get(i) | + | |
| balloons.remove (i); | balloons.remove (i); | ||
| }else{ | }else{ | ||
balloons.1534509314.txt.gz · Last modified: 2018/08/17 08:35 by frchris