Tutorials to .com

Tutorials to .com » Jsp » Skills » Right java pop-up menu

Right java pop-up menu

Print View , by: iSee ,Total views: 21 ,Word Count: 273 ,Date: Wed, 26 Aug 2009 Time: 10:14 AM

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 button1 listening events,
button1.addMouseListener (new java.awt.event.MouseAdapter () (
public void mousePressed (MouseEvent e) (
button1_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 button1_mousePressed (MouseEvent e) (
/ * To the right judgments by InputEvent.BUTTON3_MASK
Is left to judge with InputEvent.BUTTON1_MASK,
* /
int mods = e.getModifiers ();
if ((mods & InputEvent.BUTTON3_MASK)! = 0)
(
popupMenu1.show (button1, e.getX (), e.getY ());
button
)
)
)
file: / / applet1.java is over


Java skills and code Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.