Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JPanel;
  8. import javax.swing.Timer;
  9.  
  10. //Jacob Baker
  11. //Lab-08
  12. //ShootingStars.java
  13.  
  14. public class ShootingStars extends JPanel implements ActionListener {
  15.    
  16.     private Star[] stars;
  17.    
  18.     public ShootingStars() {
  19.         super();
  20.         setBackground(Color.black);
  21.        
  22.         stars = new Star[100];
  23.         for (int i = 0; i < stars.length; i++) {
  24.             stars[i] = new Star(600,600);
  25.         }
  26.        
  27.         this.setPreferredSize(new Dimension(600,600));
  28.        
  29.         Timer t = new Timer(20,this);
  30.         t.start();
  31.     }
  32.    
  33.     public void paintComponent(Graphics page) {
  34.         super.paintComponent(page);
  35.        
  36.         //DRAW MOON:
  37.         page.setColor(Color.white);
  38.         page.fillOval(50, 50, 100, 100);
  39.        
  40.         page.setColor(Color.black);
  41.         page.fillOval(70, 60, 100, 100);
  42.        
  43.         //DRAW STARS:
  44.         for(int i = 0; i < stars.length; i++) {
  45.             stars[i].draw(270, page);
  46.         }
  47.    
  48.     }
  49.    
  50.     @Override
  51.     public void actionPerformed(ActionEvent e) {
  52.         for (int i = 0; i < stars.length; i++) {
  53.             stars[i].move();
  54.         }
  55.         this.repaint();
  56.     }
  57.    
  58.    
  59.  
  60.    
  61.    
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement