Hello All,
I'm trying to create three independent animations that all occur in one main frame. I have to use the following methods in my code
--- Animate ---
public interface Animate {
void move( double x, double y);
void changeConfiguration();
}
--- Drawable -----
import java.awt.Graphics2D;
public interface Drawable {
void draw(Graphics2D g2d);
}
However i'm having a bit of trouble figuring out where, and how i'm suppose to implement them in my code
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Color;
import javax.swing.JComponent;
public class ObjectA extends JComponent{
public void paintComponent( Graphics g ){
Graphics2D g2 = (Graphics2D) g;
Rectangle box1a = new Rectangle(50, 50, 100, 100);
Rectangle box1b = new Rectangle(75, 75, 50, 50);
Rectangle box2a = new Rectangle(350, 350, 100, 100);
Rectangle box2b = new Rectangle(375, 375, 50, 50);
g2.setPaint( Color.blue );
g2.fill( box1a );
g2.fill( box2a );
g2.setPaint( Color.red );
g2.fill( box1b );
g2.fill( box2b );
}
}
What i need to happen is for the two rectangles to move back and forth across frame horizontally, therefore i'm told to use the Animate method, (above) however, i can't seem to get it to work for me. I also need to create a class to call on the Object to show the animation, which i'm also having some issues with, any advice?