Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Pop-up Menus

                         

A PopupMenu is similar to a Menu as it contains MenuItem objects. The Pop-up Menu can be popped over any component while generating the appropriate mouse event rather than letting it appear at the top of a Frame. Menu class can only be added to a Frame and not to the Applet. To add it to the Applet you need to use the Swing component set. 

In the program code given below, we have used MouseEvent.isPopupTrigger() method to trigger the MouseEvent that pops up the menu. The example below shows the triggering of a pop-up menu and its activation through a command button.

 

import java.awt.*; 
import java.awt.event.*; 
import java.applet.Applet;

public class PopupMenuDemo extends Applet
    Button b; 
    TextField msg; 
    PopupAppMenu m; 
    public PopupMenuDemo(){ 
      setSize(200200)
      b = new Button("Pop-up Menu")
      add(b, BorderLayout.NORTH)
      msg = new TextField()
      msg.setEditable(false)
      add(msg, BorderLayout.SOUTH)
      m = new PopupAppMenu(this)
      add(m)
      b.addActionListener(new ActionListener(){ 
        public void actionPerformed(ActionEvent e){ 
          m.show(b, 2020)
          
  })
  addMouseListener(new MouseAdapter(){ 
    public void mousePressed(MouseEvent e){ 
      if (e.isPopupTrigger()) 
        m.show(e.getComponent(), e.getX(), e.getY())
      
      public void mouseReleased(MouseEvent e){ 
      if (e.isPopupTrigger()) 
        m.show(e.getComponent(), e.getX(), e.getY())
      
    })
    
    public static void main(String[] args){ 
    PopupMenuDemo app = new PopupMenuDemo()
    app.setVisible(true)
    
  
   
  class PopupAppMenu extends PopupMenu 
    implements ActionListener
    PopupMenuDemo ref; 
    public PopupAppMenu(PopupMenuDemo ref){ 
    super("File")
    this.ref = ref; 
    MenuItem mi; 
    add(mi = new MenuItem("Copy"))
    mi.addActionListener(this)
    add(mi = new MenuItem("Open"))
    mi.addActionListener(this)
    add(mi = new MenuItem("Cut"))
    mi.addActionListener(this)
    add(mi = new MenuItem("Paste"))
    mi.addActionListener(this)
    
    public void actionPerformed(ActionEvent e){ 
    String item = e.getActionCommand()
    ref.msg.setText("Option Selected: " + item)
    
  

Output of the program:

C:\newprgrm>javac PopupMenuDemo.java

C:\newprgrm>appletviewer PopupMenuDemo.html

Download this example.

 

 

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

Excellent material.not only this but all the topics covered are very helpful for upcoming software engineers..GOOD JOB!!!

Posted by sidhartha chandrasekhar on Monday, 03.3.08 @ 18:28pm | #51164

Latest Searches:
Tomcat deploy JSP
typecast between strin
how to reate a textfie
connect to sql databas
login session
javascript separate in
informatica
sorting program
adding label and textb
java constants
prime numbers
displaying text in a d
wireless c
give the input text fi
iterator
transposition
menu bar in java
PHP Email Systems Send
jsf selectitems
Photoshop Basics Add F
state management
excel from java
struts2.0 introduction
Photoshop Cut out imag
jstl list
Flag
codebar
Photoshop Photo Effect
java session
input in java
button onclick go to a
Spring ORM Module
ASP.NET .NET Custom Va
JtextArea enable
pdf box get text
Quartz Tutorial
Combo Box Using Ajax I
JDBC with Mysql in Ecl
PHP Site Navigation Ad
jasper report
display arraylist
jstl basics tomcat
how to read and wirte
add the ArrayList to
JSP Cookies Example
Introduction to Spring
Insert Data into Datab
source code to send te
ant pdf
ajax tree example
show calender page
richfaces a4j taglibr
jQuery To Hide the Div
gridsphere projects
for loop
Read/Write XML with DO
delete
t:htmltag
<t:dataScroller
servermail service pro
login eample code usin
file uploading code us
javaBeans class exampl
Creating a DSN for MyS
abstract class and abs
session login in jsp
velocity rules engine
CHECKLIST BOX
action form struts
HWPF
Vector
how to run applets
tree
to find the largest el
how to generate pdf fi
Framework for Java Dat
Use JFrame in JSP code
draw Polyline
standered jstl jar to
how to retrieve data f
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.