Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. package wave_generator;
  2.  
  3. import javax.swing.JFrame;
  4.  
  5. /**
  6.  * @author Vul hier jouw naam in!
  7.  * @version 1
  8.  *
  9.  */
  10.  
  11. public class WuppyWaver
  12. {
  13.     private JFrame aii_Frame;
  14.     private AiiCanvas aii_Canvas;
  15.    
  16.     private int[] m_XPositions;
  17.     private int[] m_YPositions;
  18.    
  19.     private int m_WuppyAmount;
  20.     private int[] m_YHeadings;      // needed for 'opdracht 4' and 'opdracht 5'?
  21.    
  22. ////////////////// YOUR CODE - START ///////////////////////   
  23.    
  24.     // Use this space to declare your own instance
  25.     // variables if you think you need them:
  26.    
  27.    
  28.    
  29. /////////////////// YOUR CODE - END ////////////////////////
  30.    
  31.     /**
  32.      * Instanciates our WuppyWaver and initializes + runs it.
  33.      *
  34.      * @param args      Arguments (command line input)
  35.      *
  36.      */
  37.     public static void main(String[] args)
  38.     {
  39.         WuppyWaver waver = new WuppyWaver();
  40.         waver.aiiInitialize();
  41.         waver.aiiCreateArrays();
  42.         waver.onInitialize();
  43.        
  44.         waver.aiiRun();
  45.     }
  46.    
  47. ////////////////// YOUR CODE - START ///////////////////////
  48.    
  49.     /**
  50.      * This method is called at the start of the program.
  51.      * Here, we set the initial values of our arrays:
  52.      */
  53.     private void onInitialize()
  54.     {
  55.         // Use 'm_WuppyAmount' for the amount of wuppys. In aiiInitialize, this variable gets the value 10;
  56.         int index = 0;
  57.         while(index < m_XPositions.length) {
  58.             m_YPositions[index] = 300;
  59.             m_XPositions[index] = index * 60;
  60.             m_YHeadings[index] = -1;
  61.             index++;
  62.         }
  63.     }
  64.    
  65.     /**
  66.      * This method is called about 60 times per second.
  67.      * Here we change the position of our wuppys so they seem to move:
  68.      */
  69.     private void performStep()
  70.     {
  71.         int index = 0;
  72.         while(index < m_XPositions.length) {
  73.             if(m_YPositions[index] >= 600) {
  74.                 m_YHeadings[index] = -1;
  75.             }
  76.             else if(m_YPositions[index] < 1) {
  77.                 m_YHeadings[index] = 1;
  78.             }
  79.             m_YPositions[index] = m_YPositions[index] + m_YHeadings[index] * (index+1);
  80.            
  81.             index++;
  82.         }
  83.         // Use 'm_WuppyAmount' for the amount of wuppys. In aiiInitialize, this variable gets the value 10;
  84.  
  85.     }
  86.    
  87. /////////////////// YOUR CODE - END ////////////////////////
  88.    
  89.     private void aiiInitialize()
  90.     {
  91.         // Create a new frame and add our canvas to draw on:
  92.         aii_Canvas = new AiiCanvas(this);
  93.        
  94.         aii_Frame = new JFrame("Wuppyyyy waverrrr.... !!!");
  95.         aii_Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  96.         aii_Frame.getContentPane().add(aii_Canvas);
  97.         aii_Frame.pack();
  98.         aii_Frame.setVisible(true);
  99.         m_WuppyAmount = 10;
  100.     }
  101.    
  102.     private void aiiCreateArrays()
  103.     {
  104.         if (m_WuppyAmount > 0)
  105.         {
  106.             m_XPositions = new int[m_WuppyAmount];
  107.             m_YPositions = new int[m_WuppyAmount];
  108.             m_YHeadings = new int[m_WuppyAmount];   // needed for 'opdracht 4' and 'opdracht 5'?
  109.         }
  110.     }
  111.    
  112.     private void aiiRun()
  113.     {
  114.         while(true)
  115.         {
  116.             try
  117.             {
  118.                 Thread.sleep(15);
  119.             }
  120.             catch(Exception e)
  121.             {
  122.                 System.out.println("AII Thread Exception: " + e.getMessage());
  123.             }
  124.             performStep();
  125.             aii_Frame.repaint();
  126.         }
  127.     }
  128.    
  129.     public int[] aiiGetXPositions()
  130.     {
  131.         return m_XPositions;
  132.     }
  133.    
  134.     public int[] aiiGetYPositions()
  135.     {
  136.         return m_YPositions;
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement