Advertisement
janevim

prohlížeč souborů PROG 14.03.

Mar 14th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.KeyEvent;
  3.  
  4. public class Menu extends JFrame {
  5.     private JPanel mainPanel;
  6.     private JMenu menuFile;
  7.     private JMenuItem miOpenFile;
  8.  
  9.     public Menu(){
  10.         initComponents();
  11.     }
  12.     private void initComponents(){
  13.         setContentPane(mainPanel);
  14.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15.         JMenuBar menuBar = new JMenuBar();
  16.         setJMenuBar(menuBar);
  17.         menuFile = new JMenu("File");
  18.         menuFile.setMnemonic(KeyEvent.VK_F);
  19.         menuBar.add(menuFile);
  20.         miOpenFile = new JMenuItem("Open...", KeyEvent.VK_0);
  21.         menuFile.add(miOpenFile);
  22.         miOpenFile.addActionListener(e -> openFile());
  23.     }
  24.     private void openFile(){
  25.         JFileChooser fc = new JFileChooser();
  26.         fc.showOpenDialog(this);
  27.     }
  28.     public static void main(String[] args) {
  29.         Menu g = new Menu();
  30.         g.pack();
  31.         g.setVisible(true);
  32.  
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement