Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Creating inGame menu


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 NuLogic   Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 March 2012 - 05:58 AM

Hello, I just started to work with my graphical game, it is simple, but I need some information, how the game menu is created? I have been searching everywhere, but there is only explained how to create menu bars, but I need simple menu like New Game, Options for example in the middle of the screen. This is my GUI class, it contains only background and menu bar on the top, maybe someone can say, how I can implement normal one? :

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

public final class GUI {   
    JFrame frame;
   
    public GUI() {	   
	    frame();
    }
// Adding background image and JMenuBar on the top
    public void frame() {
	    frame = new JFrame("My Game");
	    try {
		  frame.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("D:/bg.png"))))); 
	    }
	    catch(IOException e) { System.out.println("No image"); }
	   
	    frame.setResizable(false);
	    frame.setSize(800, 449);
	   
	    JMenuBar menubar = new JMenuBar();
	    frame.setJMenuBar(menubar);
	    JMenu file = new JMenu("Meniu");
	    menubar.add(file);
	    JMenuItem exit = new JMenuItem("Exit");
	    file.add(exit);
	    JMenu help = new JMenu("Help");
	    menubar.add(help);
        JMenuItem about = new JMenuItem("About");
	    help.add(about);

	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	 
	    frame.setVisible(true); 
	   
	    class ExitAction implements ActionListener {
		    @Override
		    public void actionPerformed(ActionEvent e){
			    System.exit(0);
		    }
	    }
	    class AboutAction implements ActionListener {
		    @Override
		    public void actionPerformed(ActionEvent e){
			    JLabel label;
                frame = new JFrame("About");
			    frame.setResizable(false);
			    frame.setSize(200, 200);
                label = new JLabel("Author: ED");
			    Font font = new Font("Arial", Font.ITALIC, 12);
			    label.setFont(font);
			    frame.add(label);
			    frame.setBackground(Color.BLUE);
			    frame.setVisible(true);
		    }
	    }
	    exit.addActionListener (new ExitAction());
	    about.addActionListener(new AboutAction());
    }
   
}

How I you would add menu? Also I tried to put a text box, but it hides under the background, how to take it from the back?

Sponsor:

#2 6510   Members   -  Reputation: 151

Like
0Likes
Like

Posted 19 March 2012 - 08:04 AM

Hello, I just started to work with my graphical game, it is simple, but I need some information, how the game menu is created? I have been searching everywhere, but there is only explained how to create menu bars, but I need simple menu like New Game, Options for example in the middle of the screen.

If I understand correctly, then you might rather need buttons: JButton, JRadioButton, JOptionPane, JCheckBox

#3 NuLogic   Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 March 2012 - 09:15 AM

I already know, how to make that stuff, i need normal menu, which will let to select any stuff, like New Game, Load Game etc.
Posted Image

but I am a bit confused, for which functions and libraries I should search to make such like upper one? Using Java SE.

#4 6510   Members   -  Reputation: 151

Like
0Likes
Like

Posted 19 March 2012 - 09:27 AM

-> JButton with icon, without border

#5 NuLogic   Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 March 2012 - 11:08 AM

ok, I will try :) thanks for yout continuous support :)

#6 NuLogic   Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 March 2012 - 12:28 PM

Can you give advice, how to put objects other objects like buttons on the background? Because my game background is hiding that objects, they are under background, how to take them out?

#7 6510   Members   -  Reputation: 151

Like
0Likes
Like

Posted 19 March 2012 - 01:04 PM

This
frame.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("D:/bg.png")))));
is not good for creating background images.
You rather need to implement you own component, lets say inherit from JPanel, and draw the background image from inside the paint method.

#8 NuLogic   Members   -  Reputation: 100

Like
0Likes
Like

Posted 19 March 2012 - 02:15 PM

yes, I am just exactly reading about it, I will repaint that stuff :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS