我正在用java制作一个xlet应用程序,在一个场景中,当我输入右键时,我现在有一个鼠标图像。但现在我希望它在计时器上移动,我现在拥有的是一个计时器,它在刻度上打印我的图像的位置,它会正确地改变 zo x 和 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();
}
}