Skip to content
Snippets Groups Projects
Select Git revision
  • 7e034174322a099f551c4d88f2e73c0aed67e8cf
  • master default
2 results

GraphicEngine.java

  • Forked from LABOUREL Arnaud / Game engine template
    48 commits ahead of the upstream repository.
    user avatar
    bosskkev authored
    4f3658a3
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GraphicEngine.java 1.33 KiB
    package engine.graphic;
    
    import engine.Engine;
    import engine.Kernel;
    import pong.PongObject;
    
    import javax.swing.*;
    import java.awt.*;
    import java.io.IOException;
    
    public class GraphicEngine extends JFrame implements Engine {
    
        public GraphicEngine() throws IOException {
        }
    
        public void init(String windowTitle, int width, int height) throws IOException {
            // mainPanel.setBounds(850,500,122,124);
            this.setTitle(windowTitle);
            // this.setContentPane(mainPanel);
            this.setMinimumSize(new Dimension(width, height));
            // this.setContentPane(mainPanel);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
            this.pack();
            this.setResizable(false);
            this.setVisible(true);
            this.setLayout(this.getLayout());
            this.revalidate();
        }
        public void draw(ImageComponent ic) throws IOException {
            getContentPane().add(ic);
        }
    
        @Override
        public void update(){
            for (PongObject po : Kernel.gameObjects
                 ) {
                try {
                    this.draw(new ImageComponent(po.getImage(), po.getPosition(), po.getWidth(), po.getHeight()));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            repaint();
            revalidate();
        }
    
    
    }