gpt4 book ai didi

java - 从接口(interface)的方法列表中调用单个方法

转载 作者:行者123 更新时间:2023-12-01 14:53:33 25 4
gpt4 key购买 nike

有人可以解释一下为什么getStartScreen()是接口(interface) Game 中唯一的方法被添加为 MrNomGame 中的未实现方法类?

public class MrNomGame extends AndroidGame 
{
public Screen getStartScreen()
{
return new LoadingScreen(this); // Instantiate class
}
}

public abstract class AndroidGame extends Activity implements Game
{
AndroidFastRenderView renderView;
Graphics graphics;
Audio audio;
Input input;
FileIO fileIO;
Screen screen;
WakeLock wakeLock;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
int frameBufferWidth = isLandscape ? 480 : 320;
int frameBufferHeight = isLandscape ? 320 : 480;
Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
frameBufferHeight, Config.RGB_565);

float scaleX = (float) frameBufferWidth
/ getWindowManager().getDefaultDisplay().getWidth();
float scaleY = (float) frameBufferHeight
/ getWindowManager().getDefaultDisplay().getHeight();

renderView = new AndroidFastRenderView(this, frameBuffer);
graphics = new AndroidGraphics(getAssets(), frameBuffer);
fileIO = new AndroidFileIO(this);
audio = new AndroidAudio(this);
input = new AndroidInput(this, renderView, scaleX, scaleY);
screen = getStartScreen(); //unimplemented method from MrNomGame
setContentView(renderView);

PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");
}

@Override
public void onResume() {
super.onResume();
wakeLock.acquire();
screen.resume();
renderView.resume();
}

@Override
public void onPause() {
super.onPause();
wakeLock.release();
renderView.pause();
screen.pause();

if (isFinishing())
screen.dispose();
}

public Input getInput() {
return input;
}

public FileIO getFileIO() {
return fileIO;
}

public Graphics getGraphics() {
return graphics;
}

public Audio getAudio() {
return audio;
}

public void setScreen(Screen screen) {
if (screen == null)
throw new IllegalArgumentException("Screen must not be null");

this.screen.pause();
this.screen.dispose();
screen.resume();
screen.update(0);
this.screen = screen;
}

public Screen getCurrentScreen() {
return screen;
}

}

public interface Game
{
public Input getInput();
public FileIO getFileIO();
public Graphics getGraphics();
public Audio getAudio();
public void setScreen(Screen screen);
public Screen getCurrentScreen();
public Screen getStartScreen();
}

最佳答案

MrNomGame 类扩展了抽象类 AndroidGame。由于 MrNomGame 是一个具体类,因此它必须实现其父类的所有抽象方法。抽象类 AndroidGame 没有 getStartScreen() 方法的实现,因此,它被添加为 MrNomGame 类中未实现的方法。

关于java - 从接口(interface)的方法列表中调用单个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14550707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com