复制代码
- //:Button2New.java
- //Capturingbuttonpresses
- importjava.awt.*;
- importjava.awt.event.*;//Mustaddthis
- importjava.applet.*;
- publicclassButton2NewextendsApplet{
- Button
- b1=newButton("Button1"),
- b2=newButton("Button2");
- publicvoidinit(){
- b1.addActionListener(newB1());
- b2.addActionListener(newB2());
- add(b1);
- add(b2);
- }
- classB1implementsActionListener{
- publicvoidactionPerformed(ActionEvente){
- getAppletContext().showStatus("Button1");
- }
- }
- classB2implementsActionListener{
- publicvoidactionPerformed(ActionEvente){
- getAppletContext().showStatus("Button2");
- }
- }
- /*Theoldway:
- publicbooleanaction(Eventevt,Objectarg){
- if(evt.target.equals(b1))
- getAppletContext().showStatus("Button1");
- elseif(evt.target.equals(b2))
- getAppletContext().showStatus("Button2");
- //Letthebaseclasshandleit:
- else
- returnsuper.action(evt,arg);
- returntrue;//Wevehandledithere
- }
- */
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |