Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Last week's constructor method code: public MyApp() { //Create and set up the window. this.setTitle(Threads and Animation); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Display the window, centred on the screen

image text in transcribed

image text in transcribed

Last week's constructor method code:

public MyApp() {

//Create and set up the window. this.setTitle("Threads and Animation");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Display the window, centred on the screen

Dimension screensize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

int x = screensize.width/2 - WindowSize.width/2;

int y = screensize.height/2 - WindowSize.height/2;

setBounds(x, y, WindowSize.width, WindowSize.height);

setVisible(true);

}

Week #2 Assignment Create a program which performs simple random animation of coloured squares Use two classes: Threads and Animation MovingSquaresApplication extends JFrame Implements Runnable has main) method Member data includes an array of GameObject instances Constructor method does similar setup as last week's code, plus instantiates the GameObjects in the array, and creates+starts a Thread Uses a Thread to perform animation of the GameObjects by calling their move() methods Paint) method draws the GameObjects by calling their paint(Graphics g) methods GameObject Member data includes x,y,color Constructor method randomises the object's position and color Public move() method is used to randomly alter x,y members Public paint(Graphics g) method draws the object as a square using g.fillRect()

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

More Books

Students also viewed these Databases questions