我运行下面程序的时候出先了这几行Note: C:\Button3.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
不知道原因,诚心请教大家
//: Button3.java
// Matching events on button text
import java.awt.*;
import java.applet.*;
public class Button3 extends Applet {
Button
b1 = new Button("Button 1"),
b2 = new Button("Button 2");
public void init() {
add(b1);
add(b2);
}
public boolean action (Event evt, Object arg) {
if(arg.equals("Button 1"))
getAppletContext().showStatus("Button 1");
else if(arg.equals("Button 2"))
getAppletContext().showStatus("Button 2");
// Let the base class handle it:
else
return super.action(evt, arg);
return true; // We've handled it here
}
} ///:~
----------------解决方案--------------------------------------------------------
你使用了过时的API
public boolean action这个方法就是过时的,现在已经用事件模型了
----------------解决方案--------------------------------------------------------
//: Button3.java
// Matching events on button text
import java.awt.*;
import java.applet.*;
public class Button3 extends Applet implements ActionListener{
Button
b1 = new Button("Button 1"),
b2 = new Button("Button 2");
public void init() {
add(b1);
add(b2);
}
public void actionPerformed(ActionEvent evt) {
Button but=(Button)evt.getSource();
if(but.equals(b1))
getAppletContext().showStatus("Button 1");
else if(but.equals(b2))
getAppletContext().showStatus("Button 2");
// Let the base class handle it:
else
getAppletContext().showStatus("Could not found Button");
// We've handled it here
}
}
----------------解决方案--------------------------------------------------------