0% found this document useful (0 votes)
20 views4 pages

Java Menu Bar and Pull Down Example

This document contains a Java program that creates a GUI with menu bars and pull-down menus using Swing. It includes functionalities for file operations (New, Open, Save, Exit), editing options (Cut, Copy, Paste, Select All), and a Help section with an About dialog. The program is structured with a JFrame containing a JTextArea and a JMenuBar with various JMenuItems linked to action listeners for user interaction.

Uploaded by

joyalprincess
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Java Menu Bar and Pull Down Example

This document contains a Java program that creates a GUI with menu bars and pull-down menus using Swing. It includes functionalities for file operations (New, Open, Save, Exit), editing options (Cut, Copy, Paste, Select All), and a Help section with an About dialog. The program is structured with a JFrame containing a JTextArea and a JMenuBar with various JMenuItems linked to action listeners for user interaction.

Uploaded by

joyalprincess
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM-8

WRITE A JAVA PROGRAM TO CREATE MENU BARS AND PULL DOWN MENUS
SOURCE CODE
import [Link].*;
import [Link].*;
import [Link].*;
class jframe implements ActionListener
{
String text="";
JTextArea content;
JFrame jf;
JMenuBar menuBar;
JMenu fileMenu,editMenu,helpMenu;
JMenuItem newItem, openItem, saveItem, exitItem, cutItem, copyItem, pasteItem, selectallItem, aboutItem;
JButton submit;
public jframe()
{ jf=new JFrame("Menu Program");
// Create labels and text fields
content=new JTextArea(500,500);
[Link](new Font("Serif",[Link],20));
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
newItem = new JMenuItem("New");
[Link](this);
openItem = new JMenuItem("Open");
saveItem = new JMenuItem("Save");
exitItem = new JMenuItem("Exit");
[Link](this);

[Link](newItem);
[Link](openItem);
[Link](saveItem);
[Link]();
[Link](exitItem);

editMenu = new JMenu("Edit");


cutItem = new JMenuItem("Cut");
[Link](this);
copyItem = new JMenuItem("Copy");
[Link](this);
pasteItem = new JMenuItem("Paste");
[Link](this);
selectallItem = new JMenuItem("Select All");
[Link](this);

[Link](cutItem);
[Link](copyItem);
[Link](pasteItem);
[Link](selectallItem);

helpMenu = new JMenu("Help");


aboutItem = new JMenuItem("About");
[Link](this);
[Link](aboutItem);

[Link](fileMenu);
[Link](editMenu);
[Link](helpMenu);
[Link](menuBar);
[Link](new JScrollPane(content));
[Link](true);
[Link](500, 500);
}
public void actionPerformed(ActionEvent ae)
{
if([Link]().equals("New"))
{
[Link]("");
}
else if([Link]().equals("Exit"))
{
[Link](0);
}
else if([Link]().equals("Cut"))
{
text=(String)[Link]();
[Link]("");
}
else if([Link]().equals("Copy"))
{
text=(String)[Link]();
}
else if([Link]().equals("Paste"))
{
int pos=[Link]();
[Link](text,pos);
}
else if([Link]().equals("Select All"))
{
[Link]();
}
else if([Link]().equals("About"))
{
[Link](jf, "Menu Bar and Pull DownMenu Program");
}
}
}
class PL8
{
public static void main(String args[])
{
jframe j=new jframe();
}
}
PROGRAM-8-OUTPUT

You might also like