I am creating a 2D scroller game in Java. I do have experience with making games on the web using javascript, html, css and node.js, so I understand that nearly all games have a main loop updating everything. The problem is, I can't think of a way to implement a game loop into my code. Here is my code:
import javax.swing.*;
public class Main {
public static boolean isRunning = true;
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame("Oxygen - Version 1.0");
JPanel panel = new Panel();
frame.setSize(1000, 500);
frame.setResizable(false);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
import java.awt.*;
import javax.swing.*;
public class Panel extends JPanel {
public void paint(Graphics graphics) {
this.setBackground(Color.BLACK);
graphics.setColor(Color.BLUE);
graphics.fillRect(0, 0, 100, 100);
}
}
This code works fine, but where would the game loop be in this code and how often would it run?