0

I programmed a game in Java Swing using null layout. Except for a few glitches that I'm working on, it is perfectly functional and looks pretty nice. My plan: fix the few bugs, add a few extra features, then use SwingWeb or AjaxSwing to allow my game to run in a web browser using HTML/CSS/JavaScript. But after talking to some people here, I feel concerned that my game will not be displayed properly since I didn't use a layout manager. Exact placement of components works just perfect for the nature of the game, since I need to have my JLabels moving around constantly, and attempting to this with a layout manager would be very problematic - so I would like to avoid changing from my null layout if I possibly can. So before I make a decision about this, can someone explain to me the problems that I could face regarding the null layout if I proceed with my plan as described above? Note that clearly I do not intend the window of the game to be resizable, as it will be running in a browser.

Sid
  • 563
  • 1
  • 10
  • 28

2 Answers2

2

AFAIU null layouts translated to HTML could only result in the position:absolute; style.

That would work even less well in HTML than it would in Swing. HTML is supposed to flow, and once the user starts increasing or decreasing the size of the text in their browser, it would fall apart.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Well the user is not supposed to change the size of the text, it is supposed to be a fixed size. At worst, I could enforce that by using well-compressed pictures of the text (there isn't much text anyway). – Sid Jan 19 '14 at 08:07
  • 1
    Ctrl+ or Ctrl- resizes both images and text here in FF. BTW - you lose most users the moment you start telling them what they are and aren't supposed to do.. But hey, it's your game, so go for it if you want. – Andrew Thompson Jan 19 '14 at 08:13
  • +1 Okay time to stop banging the head against the wall. You have seen some of my code, I guess I can try to use a combination of layout managers, GridBagLayout for the Main Menu, GridLayout for the game itself, etc. I have some questions which don't really fit in here so if I can reach you at some StackOverflow chatroom or something I would be most grateful. – Sid Jan 19 '14 at 08:20
  • 1
    I don't chat. Part of the reason is *because* the questions on SO are subject to a vetting process. If you want to hire a personal tutor, I am available at $30 per hour (special deal - usually I charge $50+ per hour). – Andrew Thompson Jan 19 '14 at 08:23
  • That's just fair but I can't afford that, thanks for your help. – Sid Jan 19 '14 at 08:25
0

Programming with NULL layout is acceptable when you are not resizing you window or you are not using changeListeners, so avoid using the null layout. Read this