Main.java
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.io.File;
import java.io.FileReader;
import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import org.havi.ui.HScene;
import org.havi.ui.HSceneFactory;
import org.havi.ui.HScreen;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
public class Main extends DefaultHandler implements Xlet {
Graphics g;
int x = 100, y = 100;
public void startElement(String uri,
String localName,
String qName,
Attributes attributes)
throws SAXException {
g.drawString("start:uri="+uri+" localName="+localName+" qName="+qName, x, y); y+=50;
}
public void endElement(String uri,
String localName,
String qName) {
g.drawString("end:" + qName, x, y); y+=50;
}
public void characters(char[] ch, int offset, int length) {
if (offset != 0) {
g.drawString("element :" + new String(ch, offset, length), x, y); y+=50;
}
}
public void initXlet(XletContext context){
try {
HScene hs= HSceneFactory.getInstance().getFullScreenScene(
HScreen.getDefaultHScreen().getDefaultHGraphicsDevice());
g = hs.getGraphics();
g.setColor(Color.white);
g.setFont(new Font(null, Font.BOLD, 48));
hs.setVisible(true);
// 解析対象XMLファイルを指定
FileReader r = new FileReader( new File("test.xml") );
// XMLリーダを生成
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(this);
reader.setErrorHandler(this);
// 解析開始
reader.parse(new org.xml.sax.InputSource(r));
} catch (Throwable thr){
g.drawString(thr.toString(), x, y); y+=50;
}
}
public void startXlet(){ }
public void pauseXlet(){ }
public void destroyXlet(boolean unconditional){}
}
関連する項目
- 既存パッケージを使用する設定: Piccoloのような既存パッケージの組み込み方法