Hi,
When I run the following program, and change the date, the code never
reaches the System.out.println.
Does anyone know how to fix this?
Regards,
Matheas Manssen
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CDF extends MIDlet implements ItemStateListener
{
private Display display;
private Form fmMain;
private DateField dfTime;
public CDF()
{
display = Display.getDisplay(this);
// The main form
fmMain = new Form("Testing..");
// DateField with todays date as a default
dfTime = new DateField("", DateField.DATE_TIME);
dfTime.setDate(new Date());
// Add to form and listen for events
fmMain.append(dfTime);
fmMain.setItemStateListener(this);
}
public void startApp ()
{
display.setCurrent(fmMain);
}
public void pauseApp()
{ }
public void destroyApp(boolean unconditional)
{ }
public void itemStateChanged(Item item)
{
System.out.println("itemStateChanged");
}
}
Roedy Green - 29 Mar 2006 18:53 GMT
I have formatted your program so that it is more comprehensible:
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CDF extends MIDlet implements ItemStateListener
{
private Display display;
private Form fmMain;
private DateField dfTime;
public CDF()
{
display = Display.getDisplay(this);
// The main form
fmMain = new Form("Testing..");
// DateField with todays date as a default
dfTime = new DateField("", DateField.DATE_TIME);
dfTime.setDate(new Date());
// Add to form and listen for events
fmMain.append(dfTime);
fmMain.setItemStateListener(this);
}
public void startApp ()
{
display.setCurrent(fmMain);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void itemStateChanged(Item item)
{
System.out.println("itemStateChanged");
}
}
If this were an AWT program I would say
fmMain.setItemStateListener(this);
should read
fmMain.addtemStateListener(this);
But since it is a MIDLET, I don't know.
I would also check that if you are supported to an get an Item rather
than an event at your listener. That is not how AWT works.
I would check that Forms generate ItemStateChanged events not some
other sort. That is the usual problem in AWT.
Sorry I can't be more help since I don't have midlet experience.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Paul Hamaker - 29 Mar 2006 20:47 GMT
Nothing wrong with your code. Running it, as soon as you change the
time or date and hit Save, itemStateChange is called.
--------------------
Paul Hamaker, SEMM, teaching ICT since 1987
http://javalessons.com
Anoniem - 29 Mar 2006 21:22 GMT
Hi,
Thank you for your reply.
I'm running "midp -classpath c:\j2me\midp2.0fcs\classes;. CDF" in a Windows
XP commandline. I have
--
Profile Spec : MIDP-2.0
Profile Impl : 2.0 fcs
Configuration: CLDC-1.0
--
Do you use a different simulator?
Regards,
Matheas
> Nothing wrong with your code. Running it, as soon as you change the
> time or date and hit Save, itemStateChange is called.
> --------------------
> Paul Hamaker, SEMM, teaching ICT since 1987
> http://javalessons.com
Paul Hamaker - 29 Mar 2006 22:26 GMT
I ran it using the Wireless Toolkit 2.2, MIDP-1.0, originally, but 2.0
worked, too.