Javaを使用してxletアプリを作成しています。あるシーンで、右のキーを入力するとマウスが表示される画像が表示されます。しかし今、私はそれをタイマーで動かしたいと思っています、私が今持っているのはタイマーであり、目盛りでそれは私の画像の場所を印刷します、そしてそれは正しいzoxとyの変化をします。しかし、画像は描かれていません、誰かが私を助けてくれますか?これが私が持っている3つのファイルです:
これはhellotvxletクラス(主なもの)です:
package hellotvxlet;
import javax.tv.xlet.*;
import org.havi.ui.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import org.bluray.ui.event.HRcEvent;
import org.dvb.event.EventManager;
import org.dvb.event.UserEventListener;
import org.dvb.event.UserEventRepository;
import org.dvb.ui.*;
import java.util.Timer;
//import org.dvb.ui.*;
//import java.awt.event.ActionEvent;
//import org.havi.ui.event.HActionListener;
public class HelloTVXlet implements Xlet, UserEventListener{
private XletContext actueleXletContext;
public HScene scene;
int waardex = 20;
int waardey = 20;
// x; y;
MijnComponent mc = new MijnComponent("bitmap1.jpg",waardex,waardey);
// debuggen of niet ?
private boolean debug=true;
public HelloTVXlet(){
}
public void initXlet(XletContext context) throws XletStateChangeException {
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);
scene.add(mc);
}
public void startXlet () throws XletStateChangeException {
MijnTimerTask objMijnTimerTask=new MijnTimerTask ( );
Timer timer = new Timer();
timer.scheduleAtFixedRate(objMijnTimerTask ,0, 100);
//star t na 0ms, elke 100ms
if(debug) System.out.println("Xlet starten");
EventManager manager = EventManager.getInstance();
UserEventRepository repository = new UserEventRepository("voorbeeld");
repository.addKey( org.havi.ui.event.HRcEvent.VK_UP);
repository.addKey( org.havi.ui.event.HRcEvent.VK_DOWN);
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 {
}
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_UP:
System.out.println("vk up");
waardey --;
mc.setLocation(waardex, waardey);
break;
case HRcEvent.VK_DOWN:
System.out.println("vk down");
waardey ++;
mc.setLocation(waardex, waardey);
break;
case HRcEvent.VK_RIGHT:
System.out.println("vk right");
mc.setLocation(waardex, waardey);
waardex ++;
break;
case HRcEvent.VK_LEFT:
System.out.println("vk left");
mc.setLocation(waardex, waardey);
waardex --;
break;
}
}
}
}
これはMijnComponent
:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hellotvxlet;
import org.havi.ui.*;
import java.awt.*;
import org.dvb.ui.*;
/**
*
* @author student
*/
public class MijnComponent extends HComponent{
private Image bmap;
private MediaTracker mtrack;
public MijnComponent(String bitmapnaam, int x, int y){
bmap = this.getToolkit().getImage(bitmapnaam);
mtrack = new MediaTracker(this);
mtrack.addImage(bmap,0);
try{
mtrack.waitForAll();
}
catch(Exception e){
System.out.println(e.toString());
}
this.setBounds(x,y,bmap.getWidth(null),bmap.getWidth(null));
}
public void paint (Graphics g){
java.awt.Image imgjpg = this.getToolkit().getImage("bitmap1.jpg");
g.drawImage(bmap, 0,0,null);
}
/* public void MoveLeft(){
}
public void MoveRight(){
}
public void MoveUp(){
}
public void MoveDown(){
}
*/
}
これはタイマークラスです:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hellotvxlet;
import java.util.TimerTask;
/**
*
* @author student
*/
public class MijnTimerTask extends TimerTask {
HelloTVXlet xlet = new HelloTVXlet();
int waardex = 20;
int waardey = 20;
// x; y;
public void run ( )
{
System.out.println(xlet.mc.getLocation());
xlet.waardex ++;
xlet.mc.setLocation(xlet.waardex, xlet.waardey);
//int appelsap = (int) xlet.mc.getAlignmentX();
}
}