背景画像を表示するJavaコードがあります。(pizza1.png)矢印キーを押したときに変更したい(ケースHRcEvent.VK_RIGHT :)しかし、何を入力すればよいかわからないため、画像が再描画され、画像パスの文字列が変更されますが、再描画しないでください。誰かが私を助けることができますか?
public class HelloTVXlet implements Xlet, UserEventListener, ResourceClient, HBackgroundImageListener{
public String afbeelding = "pizza1.png";
private HScreen screen;
private HBackgroundDevice bgDevice;
private HBackgroundConfigTemplate bgTemplate;
private HStillImageBackgroundConfiguration bgConfiguration;
private HBackgroundImage agrondimg = new HBackgroundImage(afbeelding);
public void notifyRelease(ResourceProxy proxy){}
public void release(ResourceProxy proxy){}
public boolean requestRelease(ResourceProxy proxy, Object requestData){
return false;
}
public void imageLoaded (HBackgroundImageEvent e){
try{
bgConfiguration.displayImage(agrondimg);
}
catch (Exception s){
System.out.println(s.toString());
}
}
public void imageLoadFailed(HBackgroundImageEvent e){
System.out.println("Image kan niet geladen worden");
}
private XletContext actueleXletContext;
public static HScene scene;
int waardex = 20;
int waardey = 20;
// x; y;
// public static MijnComponent mc = new MijnComponent("sterren.PNG");
// debuggen of niet ?
private boolean debug=true;
public HelloTVXlet(){
}
public void initXlet(XletContext context) throws XletStateChangeException {
screen = HScreen.getDefaultHScreen();
bgDevice = screen.getDefaultHBackgroundDevice();
if(bgDevice.reserveDevice(this)){
System.out.println("BackgroundImage device ahs been reserved");
}
else{
System.out.println("Background image device cannot be reserved");
}
bgTemplate = new HBackgroundConfigTemplate();
bgTemplate.setPreference(HBackgroundConfigTemplate.STILL_IMAGE, HBackgroundConfigTemplate.REQUIRED);
bgConfiguration = (HStillImageBackgroundConfiguration)bgDevice.getBestConfiguration(bgTemplate);
try{
bgDevice.setBackgroundConfiguration(bgConfiguration);
}catch(java.lang.Exception e){
System.out.println(e.toString());
}
if(debug) System.out.println("Xlet initialiseren");
this.actueleXletContext = context;
HSceneTemplate sceneTemplate = new HSceneTemplate();
sceneTemplate.setPreference(HSceneTemplate.SCENE_SCREEN_DIMENSION, new HScreenDimension(1.0f, 1.0f), HSceneTemplate.REQUIRED);
sceneTemplate.setPreference(HSceneTemplate.SCENE_SCREEN_LOCATION, new HScreenPoint(0.0f,0.0f), HSceneTemplate.REQUIRED);
scene = HSceneFactory.getInstance().getBestScene(sceneTemplate);
}
public void startXlet () throws XletStateChangeException {
agrondimg.load(this);
if(debug) System.out.println("Xlet starten");
EventManager manager = EventManager.getInstance();
UserEventRepository repository = new UserEventRepository("voorbeeld");
repository.addKey( org.havi.ui.event.HRcEvent.VK_RIGHT);
repository.addKey( org.havi.ui.event.HRcEvent.VK_LEFT);
manager.addUserEventListener(this, repository);
scene.validate();
scene.setVisible(true);
}
public void pauseXlet() {
}
public void destroyXlet(boolean unconditional)throws XletStateChangeException {
agrondimg.flush();
}
public void userEventReceived(org.dvb.event.UserEvent e){
if(e.getType() == KeyEvent.KEY_PRESSED){
System.out.println("pushed button");
switch (e.getCode()){
case HRcEvent.VK_RIGHT:
System.out.println("vk right");
if(afbeelding == "pizza1.png"){
afbeelding = "pizza2.png";
System.out.println("1 naar 2");
}else
if(afbeelding == "pizza2.png"){
afbeelding = "pizza3.png";
System.out.println("2 naar 3");
}else
if(afbeelding == "pizza3.png"){
afbeelding = "pizza4.png";
System.out.println("3 naar 4");
}else
if(afbeelding == "pizza4.png"){
afbeelding = "pizza1.png";
System.out.println("4 naar 1");
};
break;
case HRcEvent.VK_LEFT:
System.out.println("vk left");
break;
}
}
}
}