How to create menu and menu items in java

elm Seekho

Here is a complete program of java through this you would be able to know that how to create menus and menu items in java. How to connect different java programs in one main frame. Here is a complete list of actions that are performed through this program.
1. How to create Menu bar,
2. How to declare different menu items,
3. How to set frame bounds,
4. How to add window listener in java,
5. How to add menu items in java,
6. How to add different action performed against menu items,
7. How to add action performed against different buttons in java,
8. How to connect different java programs in one frame,
9. How to add different java frames in one main frame,

Here is a complete program of java through this you would be able to know that how to create menus and menu items in java. How to connect different java programs in one main frame. Here is a complete list of actions that are performed through this program.

Complete List of actions performed through this java program.

  1. How to create Menu bar,
  2. How to declare different menu items,
  3. How to create super frame in java,
  4. How to set frame bounds,
  5. How to set x-axis and y-axis of java frame,
  6. How to add window listener in java,
  7. How to use menu in java awt classes,
  8. How to set title of frame in java,
  9. How to add menu items in java,
  10. How to set frame back ground color in java,
  11. How to add different menu items in java,
  12. How to connect different java programs in one frame,
  13. How to add different java frames in one main frame,
  14. How to set font color in java,
  15. How to set font weight in java,
  16. How to add different action performed against menu items,
  17. How to add action performed against different buttons in java,
  18. How to create action events in java,
  19. How to create main class in java,
  20. How to create label in java,

Complete Java Programs for creating menus and menu items.

import java.awt.; import java.awt.event.;
class myframe extends Frame implements ActionListener
{
MenuBar mbar;
Menu ColorMenu, operationMenu,PizzaMenu,SampleMenu,CalculatorMenu;
MenuItem red,green,blue,black,pizza,list,Pizza,combolist,hello,kaleem,calculate,Calculator;
Label lb;

myframe()
{
super(“Elmseekho”);
super.setFont(new Font(“Perpetua”,Font.BOLD,18));
setBackground(new Color(250,150,100));
setBounds(50,50,1100,700);
setLayout(null);

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
dispose();
}
});

mbar=new MenuBar();

Colors Menui
Colors Menu Items
ColorMenu= new Menu("Colors");
       red=new MenuItem("Red");
       red.addActionListener(this);       
       green=new MenuItem("Green");
       green.addActionListener(this);

       blue=new MenuItem("Blue");
       blue.addActionListener(this);

       black=new MenuItem("Black");
       black.addActionListener(this);
Operation Menu Items
Operation Menu Items
operationMenu = new Menu("Operation");      
 list = new MenuItem("List");
       list.addActionListener(this);

       combolist = new MenuItem("ComboList");
       combolist.addActionListener(this);

       operationMenu.add(list);
       operationMenu.add(combolist);  
PizzaMenu = new Menu("Pizza");      
       Pizza=new MenuItem("Pizza quantity");
       Pizza.addActionListener(this);

      pizza = new MenuItem("Pizza");
      pizza.addActionListener(this);

      kaleem=new MenuItem("Kaleem");
      kaleem.addActionListener(this);

     PizzaMenu.add(Pizza); 
     PizzaMenu.add(pizza);
     PizzaMenu.add(kaleem);         
Pizza Menu Items
Pizza Menu Items

SampleMenu=new Menu(“Sample”);
hello=new MenuItem(“Hello”);
hello.addActionListener(this);
SampleMenu.add(hello);

CalculatorMenu=new Menu(“Calculator”);
calculate=new MenuItem(“Complete Cal..”);
calculate.addActionListener(this);

Calculator=new MenuItem(“Calculator”);
Calculator.addActionListener(this);

alculatorMenu.add(calculate);
CalculatorMenu.add(Calculator);

ColorMenu.add(red);
ColorMenu.add(green);
ColorMenu.add(blue);
ColorMenu.add(black);

mbar.add(ColorMenu);
mbar.add(operationMenu);
mbar.add(PizzaMenu);
mbar.add(SampleMenu);
mbar.add(CalculatorMenu);

setMenuBar(mbar);

lb=new Label(“MUHAMMAD KALEEM”);
lb.setBounds(550,640,300,35);
lb.setFont(new Font(“Monotype Corsiva”,Font.BOLD,26));

add(lb);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==red)
{
setBackground(new Color(255,0,0));
}
if(ae.getSource()==green)
{
setBackground(new Color(0,255,0));
}
if(ae.getSource()==blue)
{
setBackground(new Color(0,0,255));
}
if(ae.getSource()==black)
{
setBackground(new Color(10,10,10));
}

if(ae.getSource()==list)
{
new listframe();
}
if(ae.getSource()==combolist)
{
new comboframe();
}

if(ae.getSource()==Pizza)
{
new chkframe();
}
if(ae.getSource()==pizza)
{
new pizzaframe();
}
if(ae.getSource()==hello)
{
new hframe();
}
if(ae.getSource()==kaleem)
{
new kframe();
}
if(ae.getSource()==calculate)
{
new calframe();
}
if(ae.getSource()==Calculator)
{
new Calculator();
}
}
}

class menu
{
public static void main(String str[])
{
myframe f=new myframe();
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Next Post

AIOU 8602 B.ed Assignment-2

Education Assessment and Evaluation (8602) B.ed 1.5 Years Spring, 2017. Here you will find updated assignments of Allama Iqbal University. AIOU Latest assignments 2019. B.ed Assignments 2019. AIOU spring assignments 2019. AIOU autumn assignments 2019. You may also like: AOIU 8602 Assignment 01 |Research Methods in Education. 1. Virtual University Admissions 2. Virtual University Fee Structure 3. NCBA&E Latest Admission 2019 4. University of Sargodha Results announcement 2019 5. Hamdard University Admissions 2019