Skip to main content

HOW TO MAKE AN ANIMATION IN JAVA






TODAY I WILL BE SHOWING YOU HOW TO MAKE AN ANIMATION USING JAVA.




  1. import javax.swing.*;
  2. import java.awt.*;

  3.  final public class Test1 {

  4.     JFrame frame;
  5.     DrawPanel drawPanel;

  6.     private int A = 9;
  7.     private int B = 5;

  8.     boolean Up = false;
  9.     boolean Down = true;
  10.     
  11.     public static void main(String[] args) {
  12.         new Test1().go();
  13.     }
  14.     private DrawPanel DrawPanel;

  15.     private void go() {
  16.         frame = new JFrame("SHAPE ANIMATION");
  17.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18.         DrawPanel = new DrawPanel();

  19.         frame.getContentPane().add(BorderLayout.CENTER, DrawPanel);

  20.         frame.setVisible(true);
  21.           frame.setResizable(false);
  22.         frame.setSize(200, 200);
  23.         frame.setLocation(175, 55);b
  24.         moveANIME();
  25.     }

  26.     class DrawPanel extends JPanel {
  27.         public void paintComponent(Graphics g) {
  28.            
  29.  g.setColor(Color.BLUE.darker());  
  30.             g.fillRect(0, 0, this.getWidth(), this.getHeight());
  31.             g.setColor(Color.blue.darker());
  32.             g.fillOval(3, 5, this.getWidth()-6, this.getHeight()-6);
  33.             g.setColor(Color.RED.brighter());
  34.             g.fillRect(10, 6, this.getWidth()-12, this.getHeight()-12);
  35.              g.setColor(Color.black.brighter());
  36.             g.fillOval(B, 10, 9, 7);
  37.             
  38.              g.setColor(Color.black.brighter());
  39.             g.fillOval(11, B, 9, 7);
  40.             
  41.             g.setColor(Color.black.brighter());
  42.             g.fillOval(80, B, 9, 7);
  43.              g.setColor(Color.black.brighter());
  44.             g.fillOval(B, B, 9, 7);
  45.         }
  46.     }

  47.     private void moveANIME() {
  48.         while(true){
  49.         
  50.             if(B >= 260){
  51.                 Up = true;
  52.                 Down = false;
  53.             }
  54.             if(B <= 7){
  55.                 Up = false;
  56.                 Down = true;
  57.             }
  58.             if(Up){
  59.                 B--;
  60.             }
  61.             if(Down){
  62.                 B++;
  63.             }
  64.             try{
  65.                 Thread.sleep(12);
  66.             } catch (Exception exc){}
  67.             frame.repaint();
  68.         }
  69.     }
  70. }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Creative Commons License
HOW TO MAKE AN ANIMATION IN JAVA USING NETBEANS by Mohammed Ibrahim Mirza Beig is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://www.wired2tech.org/2017/12/how-to-make-animation-in-java-using.html?m=1.

Comments

Popular posts from this blog

HOW TO MAKE ARTIFICIAL INTELLIGENCE WITH NOTEPAD++

OK so when you hear artificial intelligence you automatically think a super high-tech robot; well today i'm gonna show just how simple artificial intelligence actually is.

STEP 1: open notepad++ and copy the following code.
fname=inputbox ("komichiwa")
fname=inputbox ("i am ASUNA")
fname=inputbox ("whats your name")
fname=inputbox ("thats a good name")
fname=inputbox ("do you like anime or manga?")
fname=inputbox ("thats cool")
fname=inputbox ("pi=3.14")
fname=inputbox ("4*8=?")
fname=inputbox ("32")
fname=inputbox ("what is the capital of RUSSIA")
fname=inputbox ("MOSCOW")
fname=inputbox ("what is BERLIN")
fname=inputbox ("the capital of GERMANY")
fname=inputbox (" i^5=?")
fname=inputbox ("i")
fname=inputbox ("what is your favorite anime?")
fname=inputbox ("cool!!")
fname=inputbox ("what is your favorite manga")
fname=inp…

How to make cool HTML animations

today we"ll be doing html animations. although animation is considered quite difficult its actually fairly simple. And as always just copy the code and if you have any issues or concerns just comment and we"ll get right back to you.image as backgroundAWESOME!!AWESOME!!AWESOME!!AWESOME!!ALWAYS LEARN AT WIRED2TECH!!ALWAYS LEARN AT WIRED2TECH!!ALWAYS LEARN AT WIRED2TECH!!ALWAYS LEARN AT WIRED2TECH!! check out wired2tech where youll always learn something new and usefull:) AWESOME!!AWESOME!!AWESOME!!









<!DOCTYPE html> <html> <head> <title>image as background</title>  <marquee behavior="alternate">AWESOME!!</marquee>  <marquee behavior="alternate">AWESOME!!</marquee>  <marquee behavior="alternate">AWESOME!!</marquee>  <marquee behavior="alternate">AWESOME!!</marquee>  <marquee behavior="alternate">ALWAYS LEARN AT WIRED2TECH!!</marquee>  <marquee beha…

Animated HTML Dialog

CODE:

"HTML"


<html>
<body>

<h1>ANIMATED TEXT JS</h1>

<button onclick="typeWriter()">ACTIVATE</button>

<style>
@import url('https://fonts.googleapis.com/css?family=Press+Start+2P');
</style>
<link rel="stylesheet" href="css13.css">
<body style ="background-color: orange;">

<p id="OPEN"></p>

<script>
var a = 0;
var text = 'VISIT WIRED2TECH.ORG TO LEARN TO CODE.This project was made by: Mohammed Ibrahim Mirza Beig.This project used the font "Press Start 2P" which is licensed under the open font license and was obtained from google fonts.';
var frameSD = 60;
function typeWriter() {
  if (a < text.length) {
    document.getElementById("OPEN").innerHTML += text.charAt(a);
    a++;
    setTimeout(typeWriter, frameSD);
  }
}
</script>
</body>
</html>


"CSS"

h1{ color:gold; -webkit-text-fill-…