Posted by: Ayus April 14, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        
@java_help

60% is complete. Rest you complete by urself.{just copy/paste]. if you dont understand, post again.


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class DemoGui extends JFrame implements ActionListener
{
    private JMenuBar menu;
    private JMenu m1,m2,m3;
    private JMenuItem Open,SaveAs,Exit,FontType,TextAreaColor, Plain, Bold,Italic;
    private JPanel pMain,pNorth,pCenter;
    private JTextArea tac;
   
    public DemoGui()
    {
      //menu bar and menu item initialization
      menu = new JMenuBar();
      m1 = new JMenu("File");
      m2 = new JMenu("Style");
     

          Open = new JMenuItem("Open");
          Open.addActionListener(this);
      SaveAs = new JMenuItem("SaveAs");
          Exit = new JMenuItem("Exit");

          FontType = new JMenu("FontType");
          TextAreaColor = new JMenu("TextAreaColor");
      
      Plain = new JMenuItem("Plain");
          Bold = new JMenuItem("Bold");
          Italic = new JMenuItem("Italic");


      //text area initialization
          tac = new JTextArea(2,3);
      tac.setText("Your Text ");
     
      //initialization panel

       pNorth = new JPanel();
           pCenter = new JPanel();
            //add menuitem to menu

       m1.add(Open);
       m1.add(SaveAs);
           m1.add(Exit);

  
           FontType.add(Plain);
           FontType.add(Bold);
           FontType.add(Italic);

           m2.add(FontType);
           m2.add(TextAreaColor);
  


       menu.add(m1);
       menu.add(m2);



     
       pCenter.setLayout(new BoxLayout(pMain,BoxLayout.Y_AXIS));
           pCenter.setBorder(BorderFactory.createTitledBorder("TEXT AREA"));
       pCenter.setLayout(new GridLayout(2,0));
       pCenter.add(tac);

       pNorth.setBackground(Color.white);

       pNorth.add(menu);

       this.getContentPane().add(pCenter,"Center");
       this.getContentPane().add(pNorth,"North");

       this.setSize(400,300);
       this.setResizable(false);
       this.setLocation(150,150);
       this.setTitle("MENU");
       this.show();
       }

       public static void main(String[] args)
       {
         try{
                 DemoGui lg = new DemoGui();
                 lg.show();
             }catch(Exception e){
                 System.out.println("Exception:\t"+e);
               }
             }

        public void actionPerformed(ActionEvent e) {
        if(e.getSource()==Open){
          JOptionPane.showMessageDialog(this,
                            "Rest you do by urself{one sub-menu and file opening a file: use JFileChooser)",
                            "Give a TRy",
                            JOptionPane.INFORMATION_MESSAGE);

          System.out.println("HelloS");

      }
      if(e.getSource()==Exit){
        System.exit(0);
      }
    }
}

Read Full Discussion Thread for this article