Crenox

Winston Tutorial 8

Apr 19th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. package com.samkough.main;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6.  
  7. @SuppressWarnings("serial")
  8. public class Win extends JFrame
  9. {
  10. private static final int WIDTH = 600;
  11. private static final int HEIGHT = 600;
  12.  
  13. JMenuBar mb1;
  14. JMenu m1;
  15. JMenuItem mi1;
  16.  
  17. public static void main(String args[])
  18. {
  19. Win frame = new Win();
  20.  
  21. frame.setVisible(true);
  22. frame.setSize(WIDTH, HEIGHT);
  23. frame.setTitle("Menu Bar");
  24. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25. frame.setLocationRelativeTo(null);
  26. }
  27.  
  28. public Win()
  29. {
  30. setLayout(new FlowLayout());
  31.  
  32. mb1 = new JMenuBar();
  33. setJMenuBar(mb1);
  34.  
  35. m1 = new JMenu("File");
  36. mb1.add(m1);
  37.  
  38. mi1 = new JMenuItem("Exit");
  39. m1.add(mi1);
  40.  
  41. event e = new event();
  42. mi1.addActionListener(e);
  43. }
  44.  
  45. public class event implements ActionListener
  46. {
  47. public void actionPerformed(ActionEvent e)
  48. {
  49. System.exit(0);
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment