Skip to main content

Beginner's problem

2 replies [Last post]
abhijith_komarla
Offline
Joined: 2009-12-07
Points: 0

Hi everyone,

I'm new to OCAP and vidiom workbench. This is my very first program and nothing is getting printed in the output screen. Please go through the code and help me.
And please suggest me some links where I can learn more about XLets.

package org.ocapproject.xlet;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.tv.xlet.Xlet;
import javax.tv.xlet.XletContext;
import javax.tv.xlet.XletStateChangeException;
import org.havi.ui.HScene;
import org.havi.ui.HSceneFactory;
import org.havi.ui.HStaticText;
import org.havi.ui.HVisible;

public class Sample extends Component implements Xlet
{

private static final long serialVersionUID = 1L;

private HScene scene ;

private HStaticText lUname;

public Sample()
{
// Does nothing extra.
}

public void initXlet(XletContext ctx) throws XletStateChangeException
{
try
{
scene = HSceneFactory.getInstance().getDefaultHScene();
setBounds(scene.getBounds());

scene.setBackgroundMode(HVisible.BACKGROUND_FILL);
lUname = new HStaticText("User Name");
lUname.setBounds(50, 50, 100, 100);
lUname.setVisible(true);

scene.add(lUname);
}
catch (Exception ex)
{
ex.printStackTrace();
throw new XletStateChangeException(ex.getMessage());
}
}

public void startXlet() throws XletStateChangeException
{
try
{
scene.setVisible(true);
scene.show();
} catch (Exception ex)
{
ex.printStackTrace();
throw new XletStateChangeException(ex.getMessage());
}
}

public void pauseXlet()
{
scene.setVisible(false);
}

public void destroyXlet(boolean forced) throws XletStateChangeException
{
try
{
scene.setVisible(false);
scene.removeAll();

} catch (Exception ex)
{
ex.printStackTrace();
throw new XletStateChangeException(ex.getMessage());
}
}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
amirn
Offline
Joined: 2009-05-06
Points: 0

Your example is almost correct.

When using the Default HScene there is NO guarantee the returned HScene's size will be set. So your scene.getBounds() may return incorrect (or zero) values.

Instead of this setBounds(scene.getBounds());
Try just doing this setBounds(0,0,640,480).

You can also create your HScene using HSceneTemplate and querying the current HAVi GraphicConfiguration to make sure you will create a full screen HScene that match the graphics resolution.

csweeney
Offline
Joined: 2009-04-11
Points: 0

Please consider using the OCAP-RI SDK, Nov2009 Release.

The installer is available at http://download.java.net/opencable/ocap-ri/builds/Nov2009SDK-Setup.exe
and the quickstart guide is at https://ocap-ri.dev.java.net/files/documents/9620/145371/file_145371.dat... .

Follow the directions to create a "HelloWorld" Xlet. This will get you started.