Jump to content
  • Advertisement
Sign in to follow this  
NuLogic

Creating inGame menu

This topic is 2432 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites
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.
3400027440_84edc00573.jpg

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!