Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.JFrame;
- public class MovingSquaresApplication extends JFrame implements Runnable {
- private static final Dimension WindowSize = new Dimension(600,600);
- private static final int NUMGAMEOBJECTS = 30;
- private GameObject[] GameObjectsArray = new GameObject[NUMGAMEOBJECTS];
- public MovingSquaresApplication(){
- //Create and set up the window.
- this.setTitle("Moving Squares");
- 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);
- for (int i = 0; i < NUMGAMEOBJECTS; i++){
- GameObjectsArray[i] = new GameObject();
- }
- Thread t = new Thread(this);
- t.start();
- }
- public static void main(String[] args){
- MovingSquaresApplication app = new MovingSquaresApplication();
- }
- public void run(){
- while(true){
- try {
- for (int a = 0; a < NUMGAMEOBJECTS; a++){
- GameObjectsArray[a].move();
- }
- Thread.sleep(16);
- } catch (InterruptedException e) {
- }
- this.repaint();
- }
- }
- public void paint(Graphics g){
- g.clearRect(0, 0, 600, 600);
- for(int z = 0; z < NUMGAMEOBJECTS; z++){
- GameObjectsArray[z].paint(g);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement