Advertisement
Guest User

FensterMitAnimation

a guest
Nov 3rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.lang.Math;
  4.  
  5. public class BauplanFensterMitAnimation extends JFrame {
  6.  
  7.     int x = 140;
  8.     int y = 140;
  9.     double z = 0;
  10.     int j = 0;
  11.     int k = 160;
  12.     int i = 0;
  13.  
  14.    
  15.     VorlageBall ball = new VorlageBall();
  16.    
  17.     public BauplanFensterMitAnimation() {
  18.    
  19.         this.setTitle("Fenster mit einer Animation");
  20.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.         this.setSize(1200,1200);
  22.         this.add(ball);
  23.         this.setVisible(true);
  24.        
  25.         ballAnstupsen();
  26.         ballBewegen();
  27.        
  28.        
  29.     }
  30.    
  31.     public class VorlageBall extends JPanel {
  32.    
  33.         public void paint(Graphics g) {
  34.        
  35.             Graphics2D g2 = (Graphics2D) g;
  36.            
  37.            
  38.             g2.setColor(Color.white);
  39.             g2.fillRect(0,0,5000,5000);
  40.             g2.setColor(Color.yellow);
  41.             g2.fillRect(j,k,-200,20);
  42.             g2.setColor(Color.red);
  43.             g2.fillRect(150,230,30,610);
  44.             g2.setColor(Color.black);
  45.             g2.fillRect(0,200,200,30);
  46.             g2.setColor(Color.green);
  47.             g2.fillOval(x,y,60,60);
  48.             g2.setColor(Color.red);
  49.             g2.fillRect(0,840,8000,5);
  50.            
  51.            
  52.                        
  53.         }
  54.     }   //Ende der inneren Klasse in der die Vorlage für die Zeichnung des Balls festgelegt wird.
  55.         public void ballAnstupsen() {
  56.    
  57.         for(int i = 0; i < 138; i++){
  58.        
  59.             j = j+1;
  60.             k = k+0;
  61.            
  62.             ball.repaint();
  63.            
  64.             try{
  65.                     Thread.sleep(40);
  66.             }catch(Exception e){}
  67.            
  68.         }
  69.         }  
  70.     public void ballBewegen() {
  71.         for(int i = 0; i<288; i++) { //288 = 11,51 sekunden
  72.             x = x+1;
  73.             i = i+1;
  74.            
  75.             z = ((9.81*625*(i*i))/(2*625))*(+1)+650;
  76.          
  77.          z = Math.round(z*100)/100; // z wird gerundet
  78.          y = (int)z; //y bekommt den intenger von z da z gerundet wurde.
  79.                 System.out.println(z);
  80.                 System.out.println(y);
  81.                 z = 0;
  82.                 y = 0;
  83.        
  84.            
  85.             ball.repaint();
  86.            
  87.             try{
  88.                     Thread.sleep(40);
  89.             }catch(Exception e){}
  90.            
  91.         } //ende der for schleife
  92.     } //Ende der festlegung der Methode ballBewegen().
  93.  
  94.     } //ende ^^
  95.             //g2.setColor(Color.white);
  96.             //g2.fillOval(x,y,60,60);
  97.             //25 m pro sekunde
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement