【发布时间】:2012-06-21 08:10:59
【问题描述】:
Windows 类中用于 java.awt 的方法 show(); 已弃用。我可以用什么代替?
package adventure;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.*;
import java.applet.*;
// Infogar testkommentar mvh Holger 2012-06-20 kl 19.03
public class Adventure extends Frame {
private static final long serialVersionUID=100L;
public Adventure() {
setSize(850, 440);
World world = new DungeonWorld ( this );
Person me = new Person( world, "You", null );
show();
me.goTo("Dungeon");
add( new Player( world, me ) );
addWindowListener(new MyWindowAdapter ());
}
class MyWindowAdapter extends WindowAdapter {
public void windowClosing (WindowEvent e) {
System.exit(0);
}
}
// Load an image from the net, making sure it has already been
// loaded when the method returns
public Image loadPicture ( String imageName ) {
Image im = null;
// Load the image from the net
try {
URL imageSource = new URL( "http://www...xxx/"
+ imageName );
try {
im = createImage( (ImageProducer) imageSource.getContent());
} catch (IOException e) {}
} catch (MalformedURLException e ) { }
// Wait to ensure that the image is loaded
MediaTracker imageTracker = new MediaTracker( this );
imageTracker.addImage( im, 0 );
try {
imageTracker.waitForID( 0 );
}
catch( InterruptedException e ) { }
return im;
}
// Load and play a sound from /usr/local/hacks/sounds/
public void playSound (String name) {
URL u = null;
try {
u = new URL("file:" + "/usr/local/hacks/sounds/" + name + ".au");
} catch (MalformedURLException e ) { }
AudioClip a = Applet.newAudioClip(u);
a.play();
}
public static void main (String[] args) {
System.out.println("test");
new Adventure();
}
}
【问题讨论】:
-
如您所知,该方法已被弃用,您必须对 API 有一定的访问权限。如果您阅读第一个短语,您将看到该使用什么...
-
我想你应该先开始阅读 Javadoc。
-
我知道有文档,但我想从一个人那里得到答案。有时一个人知道的不仅仅是文档。例如,到处都有未记录的东西。感谢 cmets。
标签: java graphics window deprecated