Java 2D animation 🎞️

preview_player
Показать описание
Java animation tutorial 2D GUI swing beginners

#Java #animation #tutorial #2D #GUI #swing #beginners
Рекомендации по теме
Комментарии
Автор


public class Main{

public static void main(String[] args) {

new MyFrame();

}
}

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);
}
}

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 = 1;
int yVelocity = 1;
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();
}
}

BroCodez
Автор

the satisfying moment when the alien perfectly hits the corner of the screen

niratomata
Автор

Simple the best programming videos! 100% Certain! Thank you Bro Code!, I have learned more with YOU with a few videos than with many programming books combined! You always Straight to the point, total knowledge, and nice manners for teaching!

mypythonplace
Автор

This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

pavelkvasnicka
Автор

I like your explanations. You are simplifying one main method of designing in Java, which helps to many beginners by programing. One High point for you bro👍

ljront
Автор

you got me when you said "I hate awkward silences" XD

naikels
Автор

I just needed to learn how to animate a line moving in a circle but this helped!

micahdavis
Автор

very helpful as always!
could I ask you cover rotating images/icons in future videos? tried various methods for the past hour, and I don't know how to implement any of the methods I came across

catea
Автор

Thank you for this. This video got to the point fast and the script is small and just what I need.

pleasedontwatchthese
Автор

The constructor Timer(10, this) is undefined
The method start() is undefined for the type Timer

GoaNights
Автор

I am very happy for the video, it allowed me to understand enough things. Thanks again!

holohien
Автор

Thanks! Doing a great job
Can you provide the link where u download the images

wangobaloch
Автор

thank you . this is very helpful and easy to understand.

nawfalnjm
Автор

Awesome. Marvelous. Splended. Thank you very much bro code!

shaynazoedeguzman
Автор

How do we get the icons for the project? I've been searching far and wide and I can't seem to find one that works for the code 😭 🙏

ZeNItSu-wt
Автор

Thank you very much for this tutorial. I need it for one little program that i hope to write in the next days. I will write the URL of this video if i will be successful in my project.
You have the great gift to explain very difficult things in a very simple way.

Thanks you again; Mr. Bro Code!!!

Paolo Maria Guardiani

Pymmusic
Автор

I Want You To Turn This into a Software and Publish it for Windows, Microsoft and MacOS

cyanuranus
Автор

My notification is broken, the notification came 23secs ago and bro code's comment was 17hr ago wth

noisyguest
Автор

Hey bro, love your tutorials, and love your channel! You're so good, everybody of all ages can learn from you! I just have on question (not related to your video, nor teaching skills).

I Want to make a trail that follows the enemy and makes a path of it, but how would I do that? I'm tried making a line, but I'm having trouble making it follow behind the character, and I'm having trouble making the previous lines stay, as the background (I think) keeps painting over it!



Also, is there a way to clone the enemy, like multiple new instances of it, maybe to make a game like space invaders with it?

Rohan-Prabhala
Автор

Yo bro your playlist need some changes timer vid needs to be before in the 2D animation... I don't get the velocity thing and timer thing here

mahimasingh