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?