#diff between 2 classes

1 messages · Page 1 of 1 (latest)

opaque vessel
#

can someone please tell me what the difference between these 2 main classes are and why one supports a KeyListener and the other doesn't?

public class Main {
    public static void main(String[] args) {
        JFrame window = new JFrame("Offbrand Tetris");

        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setResizable(false);
        window.setUndecorated(true);

        GamePanel gp = new GamePanel();
        gp.launchGame();
        window.add(gp);
        window.pack();

        window.setLocationRelativeTo(null);
        window.setVisible(true);

        GamePanel.device.setFullScreenWindow(window);
    }
}``` Main 1 (supports)

```java
public class Main {
    public static void main(String[] args) {
        JFrame window = new JFrame();
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setResizable(false);
        window.setTitle("Game");

        window.setLocationRelativeTo(null);
        window.setUndecorated(true);
        window.setVisible(true);

        GamePanel gp = new GamePanel();
        window.add(gp);

        window.pack();

        GamePanel.device.setFullScreenWindow(window);

        gp.startGameThread();
    }
}``` Main 2 (doesn't support)

(GamePanel extends JPanel implements Runnable)
sly hamletBOT
# opaque vessel can someone please tell me what the difference between these 2 main classes are ...

Detected code, here are some useful tools:

Formatted code
public class Main {
  public static void main(String[] args) {
    JFrame window = new JFrame("Offbrand Tetris");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setResizable(false);
    window.setUndecorated(true);
    GamePanel gp = new GamePanel();
    gp.launchGame();
    window.add(gp);
    window.pack();
    window.setLocationRelativeTo(null );
    window.setVisible(true);
    GamePanel.device.setFullScreenWindow(window);
  }
}
#

<@&987246399047479336> please have a look, thanks.

sturdy marten
#

Have you read the JFrame javadocs? Specific instructions in there.

wise breach
wispy raptor
#

@sturdy marten your looking in the wrong place, look in the controller

bold pulsar
#

I don't know what you mean by "supports". The Main class itself, in both cases, doesn't have anything to do with being or assigning a KeyListener.

Perhaps GamePanel.launchGame() and GamePanel.startGameThread() do differrent things.

wispy raptor
#

Op's got a few topics open on the same problem, he got help on making a listener working, then did some refactoring and now it aint working no more.
Op will probably post the correct classes when op is back

opaque vessel
#
GitHub

Contribute to The-Great-K/Game development by creating an account on GitHub.

GitHub

Contribute to The-Great-K/Game development by creating an account on GitHub.

#

They are the exact same on both instances, only Main changes

twilit sand
#

It doesn't help at all that you keep creating threads

opaque vessel
#

Keep creating threads? I thought there was only one

wise breach
opaque vessel
#

Oh

#

Ig, but usually when I see a post with 100+ messages, i assume it’s been resolved

wispy raptor
#

u got 3 open or more i think at the moment

#

the bot does say that after a few hours they are gone, but when u talk in them, they reopen

opaque vessel
#

They aren’t open

sly hamletBOT
#

diff between 2 classes