0% found this document useful (0 votes)
18 views2 pages

Practical No 6: Write A Java Program Using Swing To Demostrate Creation and Use of Pop Up Menu

The document describes a Java program that demonstrates the creation and use of a pop-up menu using Swing. The program creates a JFrame window and pop-up menu with menu items for "Cut", "Copy", and "Paste". It adds a mouse listener to the frame to display the pop-up menu when the user right-clicks.

Uploaded by

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

Practical No 6: Write A Java Program Using Swing To Demostrate Creation and Use of Pop Up Menu

The document describes a Java program that demonstrates the creation and use of a pop-up menu using Swing. The program creates a JFrame window and pop-up menu with menu items for "Cut", "Copy", and "Paste". It adds a mouse listener to the frame to display the pop-up menu when the user right-clicks.

Uploaded by

Ruban Anandraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

T.Y.B.

Sc-IT

ADVANCE JAVA

ROLL NO -30

Page

24

PRACTICAL NO 6
SOURCE CODE : Write a java program using swing to demostrate creation
and use of pop up menu.
FILE NAME: JPopupMenuDemo
import java.awt.event.*;
import javax.swing.*;
public class JPopupMenuDemo
{
JFrame f;
JPopupMenu jpm;
JMenuItem mi1,mi2,mi3;
public JPopupMenuDemo()
{
f=new JFrame("Creating Popmenu");
f.setSize(500, 500);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jpm=new JPopupMenu();
mi1=new JMenuItem("Cut");
mi2=new JMenuItem("Copy");
mi3=new JMenuItem("Paste");
jpm.add(mi1);
jpm.add(mi2);
jpm.add(mi3);
mi1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {}
});
f.addMouseListener(new MouseAdapter()
{
@Override
public void mouseReleased(MouseEvent e) {
if(e.isPopupTrigger())
jpm.show(e.getComponent(),e.getX(),e.getY());
}
});
f.add(jpm);
}
public static void main(String[] args)
{
BATCH-I

2015-2016

SIES COLLEGE

T.Y.B.Sc-IT

ADVANCE JAVA

ROLL NO -30

Page

25

JPopupMenuDemo obj=new JPopupMenuDemo();

OUTPUT :

BATCH-I

2015-2016

SIES COLLEGE

You might also like