Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.KeyEvent;
- public class Menu extends JFrame {
- private JPanel mainPanel;
- private JMenu menuFile;
- private JMenuItem miOpenFile;
- public Menu(){
- initComponents();
- }
- private void initComponents(){
- setContentPane(mainPanel);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JMenuBar menuBar = new JMenuBar();
- setJMenuBar(menuBar);
- menuFile = new JMenu("File");
- menuFile.setMnemonic(KeyEvent.VK_F);
- menuBar.add(menuFile);
- miOpenFile = new JMenuItem("Open...", KeyEvent.VK_0);
- menuFile.add(miOpenFile);
- miOpenFile.addActionListener(e -> openFile());
- }
- private void openFile(){
- JFileChooser fc = new JFileChooser();
- fc.showOpenDialog(this);
- }
- public static void main(String[] args) {
- Menu g = new Menu();
- g.pack();
- g.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement