请问哪位写过没,都找了很久都没有找到,要得急,希望各位帮帮忙,要在页面中右击鼠标弹出菜单来。
问题补充:
能不能加些注释,还有jsp怎样调用呢?小妹不懂希望能更加详细一点,非常感谢!
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
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author Five
*
*/
public class PopupTest extends JFrame {
private JRadioButtonMenuItem items[];
private final Color colorValues[] =
{ Color.BLUE, Color.YELLOW, Color.RED };
private JPopupMenu popupMenu;
// set up GUI
public PopupTest()
{
super( "Using JPopupMenus" );
ItemHandler handler = new ItemHandler();
String colors[] = { "Blue", "Yellow", "Red" };
// set up popup menu and its items
ButtonGroup colorGroup = new ButtonGroup();
popupMenu = new JPopupMenu();
items = new JRadioButtonMenuItem[ 3 ];
// construct each menu item and add to popup menu; also
// enable event handling for each menu item
for ( int count = 0; count < items.length; count++ ) {
items[ count ] = new JRadioButtonMenuItem( colors[ count ] );
popupMenu.add( items[ count ] );
colorGroup.add( items[ count ] );
items[ count ].addActionListener( handler );
}
getContentPane().setBackground( Color.WHITE );
// declare a MouseListener for the window that displays
// a JPopupMenu when the popup trigger event occurs
addMouseListener(
new MouseAdapter() { // anonymous inner class
// handle mouse press event
public void mousePressed( MouseEvent event )
{
checkForTriggerEvent( event );
}
// handle mouse release event
public void mouseReleased( MouseEvent event )
{
checkForTriggerEvent( event );
}
// determine whether event should trigger popup menu
private void checkForTriggerEvent( MouseEvent event )
{
if ( event.isPopupTrigger() )
popupMenu.show(
event.getComponent(), event.getX(), event.getY() );
}
} // end anonymous inner clas
); // end call to addMouseListener
setSize( 300, 200 );
setVisible( true );
} // end constructor PopupTest
public static void main( String args[] )
{
PopupTest application = new PopupTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
// private inner class to handle menu item events
private class ItemHandler implements ActionListener {
// process menu item selections
public void actionPerformed( ActionEvent event )
{
// determine which menu item was selected
for ( int i = 0; i < items.length; i++ )
if ( event.getSource() == items[ i ] ) {
getContentPane().setBackground( colorValues[ i ] );
return;
}
}
} // end private inner class ItemHandler
} // end class PopupTest
2. var oPopup = window.createPopup();通过html隐藏对象window创建一个popup
3. 配置oPopup属性和innerHTML
- oPopBody.style.backgroundColor = "buttonface";
- oPopBody.style.border = "solid black 1px";
- oPopBody.innerHTML = ""
- +"<table cellpadding=0 cellspacing=0 border=0 width=100% style='font-size:12px;'>"
- +"<tr><td valign=middle height=20 onmouseover=/"this.bgColor='highlight';this.style.color='highlighttext';/" "
- +"onmouseout=/"this.bgColor='';this.style.color=''/" onclick=/"parent.window.open('/news/view.asp?id="+id+"');/"> 查看该新闻 </td></tr>"
- +"<tr><td bgcolor='threedshadow' height=1></td></tr>"
- +"<tr><td valign=middle height=20 onmouseover=/"this.bgColor='highlight';this.style.color='highlighttext';/" "
- +"onmouseout=/"this.bgColor='';this.style.color=''/" onclick=/"parent.document.frames['main'].location="
- +"'newsimgdel.asp?id="+id+"'/"> 删除 </td></tr><table>";
oPopBody.style.backgroundColor = "buttonface";
oPopBody.style.border = "solid black 1px";
oPopBody.innerHTML = ""
+"<table cellpadding=0 cellspacing=0 border=0 width=100% style='font-size:12px;'>"
+"<tr><td valign=middle height=20 οnmοuseοver=/"this.bgColor='highlight';this.style.color='highlighttext';/" "
+"οnmοuseοut=/"this.bgColor='';this.style.color=''/" οnclick=/"parent.window.open('/news/view.asp?id="+id+"');/"> 查看该新闻 </td></tr>"
+"<tr><td bgcolor='threedshadow' height=1></td></tr>"
+"<tr><td valign=middle height=20 οnmοuseοver=/"this.bgColor='highlight';this.style.color='highlighttext';/" "
+"οnmοuseοut=/"this.bgColor='';this.style.color=''/" οnclick=/"parent.document.frames['main'].location="
+"'newsimgdel.asp?id="+id+"'/"> 删除 </td></tr><table>";
innerHTML里是一个Table
4. 显示popup
oPopup.show(event.x, event.y, 90, 41, document.body);
5.return false;
和java没有很大的联系。
直接将javascript代码加入jsp中就可以用了。
extends是继承父类,只要那个类不是声明为final或者那个类定义为abstract的就能继承,JAVA中不支持多重继承,但是可以用接口来实现,这样就要用到implements,继承只能继承一个类,但implements可以实现多个接口,用逗号分开就行了
比如
class A extends B implements C,D,E
一个类通过关键字implements声明自己使用一个或者多个接口。在类的声明中,通过关键字extends来创建一个类的子类。 class 子类名 extends 父类名 implenments 接口名 {... } 基本上就这样用了。
class 子类名 extends 父类名 implenments 接口名
JAVA中extends 与implements有啥区别?
1. 在类的声明中,通过关键字extends来创建一个类的子类。一个类通过关键字implements声明自己使用一个或者多个接口。
extends 是继承某个类, 继承之后可以使用父类的方法, 也可以重写父类的方法; implements 是实现多个接口, 接口的方法一般为空的, 必须重写才能使用
2.extends是继承父类,只要那个类不是声明为final或者那个类定义为abstract的就能继承,JAVA中不支持多重继承,但是可以用接口来实现,这样就要用到implements,继承只能继承一个类,但implements可以实现多个接口,用逗号分开就行了
比如
class A extends B implements C,D,E
===========================================================
implements
学了好久,今天终于明白了implements,其实很简单,看下面几个例子就ok啦~~
接口的一些概念
public inerface Runner
{
}
interface Animal extends Runner
{
}
class Fish implements Animal
{
public void breather()
}
abstract LandAnimal implements Animal
{
}
class Student extends Person implements Runner
{
}
interface Flyer
{
}
class Bird implements Runner , Flyer
{
}
class TestFish
{
}
接口实现的注意点:
a.实现一个接口就是要实现该接口的所有的方法(抽象类除外)。
b.接口中的方法都是抽象的。
c.多个无关的类可以实现同一个接口,一个类可以实现多个无关的接口。
extends与implements的不同
比如
class A extends B implements C,D,E
//
class 子类名 extends 父类名 implenments 接口名
{...
}
===========================================================
A a = new B(); 结果a是一个A类的实例,只能访问A中的方法,那么又和A a = new A();有什么区别呢?
==========================================================
class B extends A
继承过后通常会定义一些父类没有的成员或者方法。
A a = new B();
这样是可以的,上传。
a是一个父类对象的实例,因而不能访问子类定义的新成员或方法。
==========================================================
假如这样定义:
class A{
int i;
void f(){}
}
class B extends A{
int j;
void f(){}//重写
void g(){}
}
然后:
B b = new B();
b就是子类对象的实例,不仅能够访问自己的属性和方法,也能够访问父类的属性和方法。诸如b.i,b.j,b.f(),b.g()都是合法的。此时b.f()是访问的B中的f()
A a = new B();
a虽然是用的B的构造函数,但经过upcast,成为父类对象的实例,不能访问子类的属性和方法。a.i,a.f()是合法的,而a.j,a.g()非法。此时访问a.f()是访问B中的f()
==========================================================
A a = new B(); 这条语句,实际上有三个过程:
(1) A a;
将a声明为父类对象,只是一个引用,未分配空间
(2) B temp = new B();
通过B类的构造函数建立了一个B类对象的实例,也就是初始化
(3) a = (A)temp;
将子类对象temp转换未父类对象并赋给a,这就是上传(upcast),是安全的。
经过以上3个过程,a就彻底成为了一个A类的实例。
子类往往比父类有更多的属性和方法,上传只是舍弃,是安全的;而下传(downcast)有时会增加,通常是不安全的。
===========================================================
a.f()对应的应该是B类的方法f()
调用构造函数建立实例过后,对应方法的入口已经确定了。
如此以来,a虽被上传为A类,但其中重写的方法f()仍然是B的方法f()。也就是说,每个对象知道自己应该调用哪个方法。
A a1 = new B();
A a2 = new C();
a1,a2两个虽然都是A类对象,但各自的f()不同。这正是1楼说的多态性的体现。
这类问题在《Java编程思想》上都讲的很清楚
===========================================================
java中能够定义接口 接口是一种变相的抽象类 接口的定义可以实现java中的多继承问题 java中类与类之间只能单继承 关键字 是extends 而对于类来说可以实现接口 关键字就用implements 表示该类实现接口 接口与接口是也可以用extends来继承
JAVA接口的实现。接口是一种特殊的抽象类,如果说抽象类定义了“是什么”,那么接口定义的就是“做什么”。因为是抽象的,所以需要实现类去实现,实现接口的类就需要在定义的时候用“implement”注明继承的哪个类
RCP中hello world模板 和带intro的模板的 区别!
今天先用 hello world模板 加了一个view视图
在creatPartControl里面加上相应代码 XML里面添加相应代码 最后在Perspective.java里面添加addView 启动运行正常 但是在 带intro的模板里面执行相同的步骤以后 启动运行,相对于代码添加前没有任何变化; 在TestView.java和Perspective.java 添加System.out.println("test"); 发现这2段test代码都没有运行 崩溃了 谁能告诉偶是怎么回事呀! |
|
看例子上,是直接添加上去的,我是对着例子添加的--论坛置顶的"RCP程序设计".
XML代码也察看了,没有问题.
期待答案!
有一个地方就是:hello和view视图的文件都在项目文件名的节点下面
intro视图的大部分文件在intro节点下面!
不知道是不是这么说,也许一些名词用错了,但意思就是那样.