Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

move gif in wave motion java

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

public class RunSwing extends JPanel {
    static int x1 = 500;
    static int y1 = 500;
    static int x2 = x1;
    static int y2 = y1;
    final static int vectorLength = 100;
    final static int sinx2 = x2;
    final static int siny2 = y2;
    static double count = 0;
    private static RunSwing run = new RunSwing();

    final Timer print = new Timer(1000, new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            //increaseSinusGraph();
            increaseClockVector();
            count+=6; //for clock for 1 second
            /*count++;//for sinus*/
            if (count % 360 == 0)
                System.out.println((count / 360) + " minute passed");
        }
    });


    RunSwing() {
        print.start();
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("amir");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(run);
        frame.setSize(1100, 700);
        frame.setVisible(true);
    }

    static void increaseClockVector() {
        double cos = Math.cos(Math.toRadians(count));
        double sin = Math.sin(Math.toRadians(count));
        y2 = siny2 + (int) (vectorLength * sin);
        x2 = sinx2 + (int) (vectorLength * cos);
    }

    static void increaseSinusGraph() {
        double sin = Math.sin(Math.toRadians(count));
        y2 = siny2 + (int) (vectorLength * sin);
        x2++;
    }

    private void createPoint(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawLine(x2, y2, x2 + 1, y2 + 1);
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(new Color(0, 0, 0));
        g.drawLine(x1, y1, x2, y2);//for clock
        /*g.drawLine(x2, y2, x2+1, y2+1);//for sinus*/
        repaint();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: reading 2d array in java 
Java :: how to change state of a Switch programmatically andoir dstudio 
Java :: getsmallestnumber 
Java :: natural log in java 
Java :: @embeddedid 
Java :: control flow graph generator 
Java :: spring boot initializr-generator example 
Java :: map indexof java 
Java :: POM error: Failure to find org.springframework.boot 
Java :: android adb is using too much cpu 
Java :: REGEX ___ get length of array in java 
Java :: Java program to print Student Info by using Class, Object, Method. 
Java :: unirest javafx 
Java :: int in double umwandeln java 
Java :: java resultset to object 
Java :: Java public no-arg constructors 
Java :: java get current free disc space 
Java :: java package keyword 
Java :: how to make easy animations in canva 
Java :: computeifabsent hashmap java 
Java :: scanner.nextInt stream api java 
Java :: android diagonal gradle 
Java :: byte array to zip java 
Java :: jwt token in android studio 
Java :: java file and stream 
Java :: Add Future Date in AndroidStudio 
Java :: compile option in android 
Java :: java overloading 
Java :: java code for image encryption & decryption 
Java :: Check if service running in the background 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =