Results 1 to 8 of 8
  1. #1
    hvince95 is offline Member
    Join Date
    Jan 2012
    Location
    Adelaide, Australia
    Posts
    17
    Rep Power
    0

    Default Creating a simple menu

    I'm making a fairly simple game with Java and when you run it, it goes straight into the game. I would like for a menu to come up first with a couple of simple buttons (New Game, Exit, etc.).
    I have a simple Frame which adds a Canvas (Java.awt.Canvas; to allow for BufferStrategy). This holds the main game loop with all its methods in it, the main loop is kicked off with the methods setup(); and runGameLoop(); from the Frame class, so it will just sit there static without those methods being called.
    In an attempt to create a menu for my game I tried making a new menu class, also extending Canvas. I would then try and add and remove the two canvases accordingly. It did not work. I then tried the setEnabled() method of the Canvas class. Also did not work. (Plus with the menu in its own class I could not refer back to the main class to add the game Canvas to the screen).

    What Should I Do? Is there a better way to create a menu, or am I on the right track and just not doing it properly?
    Thanks.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default Re: Creating a simple menu

    It did not work.
    Can you post the code that did not work and explain what the problem was with it?

    Are you using a JDialog class object for the menu that comes up first?
    Last edited by Norm; 01-19-2012 at 02:52 PM. Reason: J added

  3. #3
    hvince95 is offline Member
    Join Date
    Jan 2012
    Location
    Adelaide, Australia
    Posts
    17
    Rep Power
    0

    Default Re: Creating a simple menu

    Thanks for the reply.

    Its not that it did not work. It probably could work, its just that I dont know how to do it. And no, the class for the menu extends Canvas, there are no Dialog classes involved whatsoever (I dont even know what they are!).

    How would you normally set up a menu for a game (If possible, how would you set up the menu if you have a Main frame which holds the gameCanvas, and menuCanvas. (Alternating between the two, and possibly a third later on)).

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default Re: Creating a simple menu

    One way would be to show a JDialog window with the choices before showing the frame for the main part of the program.
    The user would enter his choices and press a button. The window would close and the user's choices would be in the JDialog class object where the rest of the program could get to them as needed.
    Last edited by Norm; 01-19-2012 at 02:52 PM. Reason: added J

  5. #5
    hvince95 is offline Member
    Join Date
    Jan 2012
    Location
    Adelaide, Australia
    Posts
    17
    Rep Power
    0

    Default Re: Creating a simple menu

    That could work very nicely, I'll have to check out how Dialog class objects work
    Thanks again!
    (Any other ideas would also be appreciated)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: Creating a simple menu

    Is there a reason an awful lot of people seem to be writing AWT programs rather than Swing ones?

  7. #7
    hvince95 is offline Member
    Join Date
    Jan 2012
    Location
    Adelaide, Australia
    Posts
    17
    Rep Power
    0

    Default Re: Creating a simple menu

    I'm writing awt because I want to use BufferStrategy

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Creating a simple menu

    Use Swing and you won't need BufferStrategy. Swing components are double buffered by default.

    And you could go through the static methods of JOptionPane. There are a couple that suit your requirement to a T, with a minimum of client code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Creating a menu in a basic 2d game
    By ResidentBiscuit in forum New To Java
    Replies: 5
    Last Post: 11-30-2011, 04:18 AM
  2. Need some help with a simple menu.
    By Medabi3 in forum Java 2D
    Replies: 1
    Last Post: 04-04-2011, 05:21 AM
  3. Creating a Main Menu - Importing
    By l3eater in forum Java Applets
    Replies: 2
    Last Post: 12-28-2010, 05:41 AM
  4. Creating menu screen for games
    By sahildave1991 in forum AWT / Swing
    Replies: 1
    Last Post: 07-02-2010, 05:36 PM
  5. Replies: 0
    Last Post: 10-28-2008, 09:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •