AWT Menu Based Application in Java with Examples

AWT Menu Based Application in Java with Examples

Table of Contents

a) Introduction to Menu Based Application
b) Example with Source Code
c) Output (Image and Video )

Creating AWT (Abstract Window Toolkit) Menu based application is similar to the SWING Menu Based Application. We have to use three classes for creating the AWT Menu Based Application. MenuBar, Menu and MenuItem are the classes required. These classes are in the java.awt package.

If you don’t know to create the AWT Frame then visit here and understand to create the frame.

Let us see the source code and its output and understand;

Source Code:

 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
package AWTComponents;

 * @author AnkitPC
import java.awt.event.*;
import java.awt.*;
public class MenuBasedAppUsingAWTDemo extends WindowAdapter {
    Frame f;
    MenuBar b;
    Menu m1,m2;
    MenuItem mi1,mi2,mi3,mi4;
    // constructor
        f= new Frame("Menu Based App With AWT");
        // set size of the frame
        // set layout
        f.setLayout(new FlowLayout());
        // registering the window event
        b=new MenuBar();
         // add menubar to frame
        m1=new Menu("File");
        m2=new Menu("Edit");
        // add menu to menubar
        mi1=new MenuItem("New");
        mi2=new MenuItem("Edit");
        mi3=new MenuItem("Hello");
        mi4=new MenuItem("Bye");
        // add menu items to the menu
    // main method
    public static void main(String[] args) {
        // call constructor
        new MenuBasedAppUsingAWTDemo();
    public void windowClosing(WindowEvent e){
Outputs are in displayed in two different form i.e. image and video to make you understand. The output image is displayed first and video is displayed at second.

awt menu bar output
awt menu bar output

Video Output:


Post a Comment