java - JFrame window doesn't show up? -
i'm building space invader style game in java. first do, i'm trying make sense of it. main requirement runs on desktop.
now i'm trying use jframe this, isn't letting me want do. when run app, show java "app" running in dock (i run osx), actual jframe window doesn't show up.
this how create window:
public gildeinvaders() { add(new panel()); settitle("gilde opleidingen space invaders"); setdefaultcloseoperation(exit_on_close); setsize(500, 500); //setsize(gildeinvaders.getconfiguration().getint("game.width"), gildeinvaders.getconfiguration().getint("game.height")); setlocationrelativeto(null); setvisible(true); setresizable(true); } public static void main(final string[] args) throws ioexception { new gildeinvaders(); } the panel i'm initiating instance of jpanel, think right approach:
public class panel extends jpanel implements runnable { // lot of variables here public panel() { addkeylistener(new tadapter()); setfocusable(true); dimension = new dimension(gildeinvaders.getconfiguration().getint("game.width"), gildeinvaders.getconfiguration().getint("game.height")); setbackground(color.black); this.initiate(); setdoublebuffered(true); } all variables, dimensions etc. defined.
i thought variables weren't defined, or didn't set visible, appears wrong.
how can window isn't showing up? did misread articles , docs?
thanks.
your code works fine me (after cutting out game-specific stuff of course).
maybe threading-problem. try calling jframes constructor way:
public static void main(final string[] args) throws ioexception { swingutilities.invokelater(new runnable() { @override public void run() { new gildeinvaders(); } }); }
Comments
Post a Comment