Advertisement
RupeshAcharya60

JMenuBar Java Swing

Mar 24th, 2023 (edited)
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5.  
  6. class MenuExample {
  7.     JFrame frame;
  8.  
  9.  
  10.     MenuExample(){
  11.         frame = new JFrame();
  12.         JMenuBar menuBar = new JMenuBar();
  13.         JMenu file = new JMenu("file");
  14.         JMenu export = new JMenu("Export");
  15.  
  16.         JMenuItem createFile = new JMenuItem("create");
  17.         JMenuItem png = new JMenuItem("as png");
  18.         JMenuItem jpg = new JMenuItem("as jpg");
  19.         export.add(png);
  20.         export.add(jpg);
  21.         menuBar.add(file);
  22.         file.add(createFile);
  23.         file.add(export);
  24.         frame.setJMenuBar(menuBar);
  25.         frame.setSize(400,400);
  26.         frame.setVisible(true);
  27.     }
  28. }
  29.  
  30. public class GUI{
  31.  
  32.     public static void main(String[] args){
  33.  
  34.         new MenuExample();
  35.  
  36.     }
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement