Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By JosAH

Thread: Improved version --MenuBar , menus & actions

  1. #1
    Agrata is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Exclamation Improved version --MenuBar , menus & actions

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.accessibility.*;
    
    
       public class MenuBarNew1 extends JFrame implements ActionListener {
    
              public static void main(String[] args)  {
    
                  new MenuBarNew1();
                                                      }
    
              // GUI creators
    
               JMenuBar jmb;
               JMenu jm;
               JMenuItem jmy;
               JRadioButtonMenuItem jradio;
               JCheckBoxMenuItem jcb;
    
              
     
              MenuBarNew1()  {
    
               jmb = new JMenuBar(); // creates a menubar
    
               jm = new JMenu("Tick"); // creates a Menu
               jm.setMnemonic(KeyEvent.VK_A);
               jm.getAccessibleContext().setAccessibleDescription("This is menu");
               jmb.add(jm);
             
    
              // creates Menu Item
               jmy = new JMenuItem("Exit",KeyEvent.VK_T);
               jmy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,ActionEvent.ALT_MASK));
               jmy.getAccessibleContext().setAccessibleDescription("To exit from window click here");
               jmy.addActionListener(this);
               jmy.setActionCommand("Exit");
               jm.add(jmy);
    
                
    
              // creates Radio Button menu item
    
                 jm.addSeparator();
    
                jradio = new JRadioButtonMenuItem("FileChooser");
                jradio.setSelected(false);
                jradio.setMnemonic(KeyEvent.VK_K);
                 jradio.addActionListener(this);
                 jradio.setActionCommand("FileChooser");
               jm.add(jradio);
    
             // creates check box menu item
    
               jm.addSeparator();
    
                  jcb = new JCheckBoxMenuItem("JTable");
                  jcb.setMnemonic(KeyEvent.VK_C);
                   
                    jcb.addActionListener(this);
                    jcb.setActionCommand("JTable");
                  jm.add(jcb);
    
               setTitle("A lucky Demo");
                setJMenuBar(jmb);
                setSize(400,400);
                setVisible(true);
    
                                                      }
    
                 public void actionPerformed(ActionEvent ae)  {
    
                 String s = ae.getActionCommand();
    
                      if(s.equals("Exit"))
                      System.exit(0);
    
    
                     if(s.equals("FileChooser"))   {
                     JFrame f1 = new JFrame("FileChooser");
                        JFileChooser fc= new JFileChooser();
                      if(jradio.isSelected()==true)  {
                     fc.setVisible(true);
                    f1.add(fc);
                    f1.pack();
                    f1.setResizable(false);
                     f1.setVisible(true);
                                                    }
    
                    if(jradio.isSelected()==false)  {
                     fc.setVisible(false);
                      f1.remove(fc);
                      f1.setVisible(false);
                                                    }
                                     }
    
                 if(s.equals("JTable"))  {
                  JFrame f1 = new JFrame("JTable");
                  JTable tab = new JTable(20,20);
    
                 if(jcb.isSelected()==true)  {
                  tab.setVisible(true);
                  f1.add(tab);
                  f1.pack();
                  f1.setResizable(false);
                  f1.setVisible(true);
                                               }
                if(jcb.isSelected()==false)  {
                 tab.setVisible(false);
                 f1.remove(tab);
                 f1.setVisible(false);
                                             }
                           }
    
                    
    
                                                              }
    
                       }
    Last edited by Eranga; 01-06-2012 at 04:13 AM. Reason: code tags added

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default Re: Improved version --MenuBar , menus & actions

    And you question is?

    kind regards,

    Jos
    Agrata likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: Improved version --MenuBar , menus & actions

    How is this improved?

    a) the code still isn't formatted.
    b) you still haven't asked a question.

    And there is no reason to create another posting, you can edit your original posting: MenuBar, menus & actions

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. MenuBar, menus & actions
    By Agrata in forum AWT / Swing
    Replies: 3
    Last Post: 01-05-2012, 02:01 PM
  2. Vertical menubar
    By Java Unknown in forum New To Java
    Replies: 0
    Last Post: 02-22-2011, 05:50 AM
  3. java -version pointing to older version
    By deepakts in forum New To Java
    Replies: 4
    Last Post: 05-06-2010, 09:59 AM
  4. OK Guys! My new and improved code.
    By Meta in forum New To Java
    Replies: 4
    Last Post: 04-07-2010, 01:06 PM
  5. About MenuBar
    By makpandian in forum AWT / Swing
    Replies: 1
    Last Post: 03-20-2009, 11:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •