Java context menu

Source: Internet
Author: User
Package test1;
Import java. AWT .*;
Import java. AWT. event .*;
Import java. Applet .*;
Public class applet1 extends applet {
Boolean isstandalone = false;
Popupmenu popupmenu1 = new popupmenu ();
Menuitem menuitem1 = new menuitem ();
Menuitem menuitem2 = new menuitem ();
Menuitem menuitem3 = new menuitem ();
Button button1 = new button ();
/** Get a parameter value */
Public String getparameter (string key, string DEF ){
Return isstandalone? System. getproperty (Key, DEF ):
(Getparameter (key )! = NULL? Getparameter (key): DEF );
}
/** Construct the applet */
Public applet1 (){
}
/** Initialize the applet */
Public void Init (){
Try {
Jbinit ();
}
Catch (exception e ){
E. printstacktrace ();
}
}
/** Component initialization */
Private void jbinit () throws exception {
Menuitem1.setlabel ("1 ");
Menuitem2.setlabel ("2 ");
Menuitem3.setlabel ("3 ");
Button1.setlabel ("button1 ");
File: // This is the listening event of button1,
Button1.addmouselistener (New java. AWT. event. mouseadapter (){
Public void mousepressed (mouseevent e ){
Button#mousepressed (E );
}
});
Popupmenu1.add (menuitem1 );
Popupmenu1.add (menuitem2 );
Popupmenu1.add (menuitem3 );
This. Add (button1, null );
Add (popupmenu1 );
}
/** Get applet information */
Public String getappletinfo (){
Return "applet information ";
}
/** Get parameter info */
Public String [] [] getparameterinfo (){
Return NULL;
}
Void button=mousepressed (mouseevent e ){
/* Right-click inputevent. button3_mask
Use inputevent. button1_mask to determine whether it is left-click,
*/
Int mod = E. getmodifiers ();
If (mod & inputevent. button3_mask )! = 0)
{
Popupmenu1.show (button1, E. getx (), E. Gety ());
Button
}
}
}
File: // applet1.java is over

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.