Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.lang.Math;
- public class BauplanFensterMitAnimation extends JFrame {
- int x = 140;
- int y = 140;
- double z = 0;
- int j = 0;
- int k = 160;
- int i = 0;
- VorlageBall ball = new VorlageBall();
- public BauplanFensterMitAnimation() {
- this.setTitle("Fenster mit einer Animation");
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setSize(1200,1200);
- this.add(ball);
- this.setVisible(true);
- ballAnstupsen();
- ballBewegen();
- }
- public class VorlageBall extends JPanel {
- public void paint(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
- g2.setColor(Color.white);
- g2.fillRect(0,0,5000,5000);
- g2.setColor(Color.yellow);
- g2.fillRect(j,k,-200,20);
- g2.setColor(Color.red);
- g2.fillRect(150,230,30,610);
- g2.setColor(Color.black);
- g2.fillRect(0,200,200,30);
- g2.setColor(Color.green);
- g2.fillOval(x,y,60,60);
- g2.setColor(Color.red);
- g2.fillRect(0,840,8000,5);
- }
- } //Ende der inneren Klasse in der die Vorlage für die Zeichnung des Balls festgelegt wird.
- public void ballAnstupsen() {
- for(int i = 0; i < 138; i++){
- j = j+1;
- k = k+0;
- ball.repaint();
- try{
- Thread.sleep(40);
- }catch(Exception e){}
- }
- }
- public void ballBewegen() {
- for(int i = 0; i<288; i++) { //288 = 11,51 sekunden
- x = x+1;
- i = i+1;
- z = ((9.81*625*(i*i))/(2*625))*(+1)+650;
- z = Math.round(z*100)/100; // z wird gerundet
- y = (int)z; //y bekommt den intenger von z da z gerundet wurde.
- System.out.println(z);
- System.out.println(y);
- z = 0;
- y = 0;
- ball.repaint();
- try{
- Thread.sleep(40);
- }catch(Exception e){}
- } //ende der for schleife
- } //Ende der festlegung der Methode ballBewegen().
- } //ende ^^
- //g2.setColor(Color.white);
- //g2.fillOval(x,y,60,60);
- //25 m pro sekunde
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement