Create 2D animation Bouncing Ball with Java code

preview_player
Показать описание
Amazing Java 2D Animation you can make today (bouncing ball animation)

I have created many 2D animations including my own interactive resume, Android Apps, games and many more. It is time for me to show you how you too can create your own animation, Apps and games with Java. It is easy and needs some of your time to dedicate and learn Java to creat the future.

Watch the video for details on the three files that must be downloaded from the first comment below.

1. Create Java Project, with Eclipse and call it Animation, or whatever.
4. Copy the three files into their proper locations per the files you created above.
5. Make sure you have added the libraries into Eclipse from Oracle.
6. You need two png images to paste in the folder which Eclipse IDE created for you. Download those two images from the following link:

7. Make sure the above images with proper names and extensions are associated to the Java code in the first comment below.

Your code should run properly on Eclipse if you follow the above steps.

If you have problem running the code or downloading the png images then comment below with your questions.

Like and subscribe for more videos like this, and advanced ones as well.

Firas Faham
=
=
Рекомендации по теме
Комментарии
Автор

// **** Main.java file #1

// 2D Animation with Java
// By: Firas Faham

public class Main{

public static void main(String[] args) {
new MyFrame();

}
}
// **** MyFrame.java file #2
// 2D Animation with Java
// By: Firas Faham
//

import java.awt.*;

import javax.swing.*;

public class MyFrame extends JFrame{

MyPanel panel;

MyFrame(){

panel = new MyPanel();


this.add(panel);
this.pack();

this.setVisible(true);
}
}

// **** MyPanel.java file #3

// 2D Animation with Java -
// By: Firas Faham
//

import java.awt.*;

import java.awt.event.*;
import javax.swing.*;

public class MyPanel extends JPanel implements ActionListener{

final int PANEL_WIDTH = 500;
final int PANEL_HEIGHT = 500;
Image enemy;
Image backgroundImage;
Timer timer;
int xVelocity = 3;
int yVelocity = 2;
int x = 0;
int y = 0;

MyPanel(){
this.setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
enemy = new
backgroundImage = new
timer = new Timer(10, this);
timer.start();
}

public void paint(Graphics g) {

super.paint(g); // paint background

Graphics2D g2D = (Graphics2D) g;

g2D.drawImage(backgroundImage, 0, 0, null);
g2D.drawImage(enemy, x, y, null);
}

@Override
public void actionPerformed(ActionEvent e) {

|| x<0) {
xVelocity = xVelocity * -1;
}
x = x + xVelocity;

|| y<0) {
yVelocity = yVelocity * -1;
}
y = y + yVelocity;
repaint();
}
}

// The end of code Make sure you copy each file above and paste it in the proper java class per video description and video content.

fifaham
visit shbcf.ru