balloons

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
balloons [2018/08/17 08:35] frchrisballoons [2024/08/25 16:53] (current) frchris
Line 1: Line 1:
 +[[https://archive.org/details/Balloons1.screenflow|Watch old video tutorial]]
 +
 CheckList: CheckList:
   - Add a method in the ''Balloon'' class called ''rise()'' which is the reverse of ''drop()''   - Add a method in the ''Balloon'' class called ''rise()'' which is the reverse of ''drop()''
Line 5: Line 7:
   - Change ''keyReleased'' so the new ''Balloon'' is near ''HEIGHT'' rather than 0.   - Change ''keyReleased'' so the new ''Balloon'' is near ''HEIGHT'' rather than 0.
   - Change ''actionPerformed'' so the balloon rises rather than falls   - Change ''actionPerformed'' so the balloon rises rather than falls
-  - Change ''actionPerformed'' so that it removes the balloon if ''balloons.get(i).getBottom() < 0'' +  - Change ''actionPerformed'' so that it removes the balloon if ''balloons.get(i).getBottom() 0'' 
   - Modify the ''paintComponent()'' method to show the number of balloons: ''g.drawString(balloons.size()+" Balloons", WIDTH-100, 20);''   - Modify the ''paintComponent()'' method to show the number of balloons: ''g.drawString(balloons.size()+" Balloons", WIDTH-100, 20);''
 Challenges:  Challenges: 
Line 12: Line 14:
   - Instead of ''Balloon'' objects, have letters drop and have them removed when you type the letter? You can keep score and make it into a game.   - Instead of ''Balloon'' objects, have letters drop and have them removed when you type the letter? You can keep score and make it into a game.
  
-<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, ActionListener public class BalloonFall extends JPanel implements KeyListener, ActionListener
 { {
Line 68: Line 71:
  public static int HEIGHT=600;  public static int HEIGHT=600;
     private Font titleFont, regularFont;     private Font titleFont, regularFont;
-    private ArrayList&lt;Balloon&gt; balloons;+    private ArrayList<Balloonballoons;
     private Timer timer;     private Timer timer;
  /**  /**
Line 82: Line 85:
     titleFont = new Font("Roman", Font.BOLD, 18);     titleFont = new Font("Roman", Font.BOLD, 18);
     regularFont = new Font("Helvetica", Font.PLAIN, 12);     regularFont = new Font("Helvetica", Font.PLAIN, 12);
-    balloons = new ArrayList&lt;Balloon&gt;();+    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, 80);  int size = Balloon.randomInt(50, 80);
  int x = Balloon.randomInt(0, WIDTH);  int x = Balloon.randomInt(0, WIDTH);
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).getBottom()  ) {+                        if ( balloons.get(i).getBottom() > HEIGHT ) {
  balloons.remove (i);  balloons.remove (i);
  }else{  }else{
balloons.1534509334.txt.gz · Last modified: by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki