So I am trying to make some kind of platform game as a practice. I managed to create a 'ball' object and a 'platform'. And with some extremely simple gravity method I managed to make the two objects interact and have the platform stop the ball from falling to its doom.

But now I would like to create a second platform, or more. After adjusting the platform method a little bit I now hope to make it more flexible so I can create as many platforms as I would like. But something is going wrong. I do not get any errors while compiling, but the code only creates 1 platform (the last one in the code, it seems). I am still looking and think there is something I have to do with the paint()-method...

This is the code in my

public class Game extends JPanel {

    Ball ball = new Ball(this);
    Platform platform = new Platform(this, 100, 280, 180, 20);
    Platform platform2 = new Platform(this, 80, 220, 150, 20);
    double speed = 2;
    double Gravity = 3;
    public Game() {
        addKeyListener(new KeyListener() {
            public void keyTyped(KeyEvent e) {
            public void keyReleased(KeyEvent e) {
            public void keyPressed(KeyEvent e) {
    private void move() {
    public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
    public void gameOver() {
        JOptionPane.showMessageDialog(this, "Game Over!", "Game Over!"
        , JOptionPane.YES_NO_OPTION);
    public static void main(String[] args) throws InterruptedException {
        JFrame frame = new JFrame("Platform");
        Game game = new Game();
        frame.setSize(300, 400);
        while (true) {


I think it goes wrong with the paint() method for platform and platform2. It looks like only the last one is created.

And this is (The first values there are a way I thought up to check whether the platform was actually created, it would appear in the upper left corner if something would go wrong with the modification of all the variables.)

public class Platform {
    private static int Y = 0;
    private static int WIDTH = 10;
    private static int HEIGHT = 10;
    private static int X = 0;
    private Game game;
    public Platform(Game game, int x, int y, int width, int height) { = game;
        Y = y;
        WIDTH = width;
        HEIGHT = height;
        X = x;
    public void paint(Graphics2D g) {
        g.fillRect(X, Y, WIDTH, HEIGHT);
    public Rectangle getBounds() {
        return new Rectangle(X, Y, WIDTH, HEIGHT);
    public int getTopY() {
        return Y;

Still looking for ways to fix it myself. And when I do I will let you guys know! But I hope somebody here can help out. :)