Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Science P6.16 Modify the ch06/animation/BlockAnimation.java program to show an animated sine wave. In the ith frame, shift the sine wave by i degrees. ch06/animation/BlockAnimation.java program

Science P6.16 Modify the ch06/animation/BlockAnimation.java program to show an animated sine wave. In the ith frame, shift the sine wave by i degrees.

ch06/animation/BlockAnimation.java program code:

import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JComponent; import javax.swing.Timer;

/* A drawing of a moving block. */ public class BlockAnimation { public static void draw(Graphics g, int frame) { final int BLOCK_WIDTH = 20; final int BLOCK_HEIGHT = 20; g.fillRect(frame, 0, BLOCK_WIDTH, BLOCK_HEIGHT); }

public static void main(String[] args) { // Do not look at the code in the main method // Your code will go into the draw method above JFrame frame = new JFrame();

final int FRAME_WIDTH = 400; final int FRAME_HEIGHT = 400;

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

final JComponent component = new JComponent() { private int frame = 0;

public void paintComponent(Graphics graph) { frame++; draw(graph, frame); } };

ActionListener timerListener = new ActionListener() { public void actionPerformed(ActionEvent event) { component.repaint(); } };

final int DELAY = 25; // 25 milliseconds between frames Timer t = new Timer(DELAY, timerListener); t.start(); frame.add(component); frame.setVisible(true); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions