概述
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://这是button1的监听事件,
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) {
/*通过InputEvent.BUTTON3_MASK对右键的判断
要判断是左键用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 弹出菜单_java右键弹出菜单的全部内容,希望文章能够帮你解决java 弹出菜单_java右键弹出菜单所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复