Home > Archive > Java Help > March 2006 > ItemStateListener
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Anoniem 2006-03-29, 7:04 pm |
| 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 2006-03-29, 7:04 pm |
| On Wed, 29 Mar 2006 17:44:26 +0200, "Anoniem" <geheim> wrote, quoted
or indirectly quoted someone who said :
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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
| |
| Paul Hamaker 2006-03-29, 7:04 pm |
| 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 2006-03-29, 7:04 pm |
| 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
"Paul Hamaker" <ph@semm.tmfweb.nl> schreef in bericht
news:1143661633.589099.295880@t31g2000cwb.googlegroups.com...
> 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 2006-03-29, 7:04 pm |
| I ran it using the Wireless Toolkit 2.2, MIDP-1.0, originally, but 2.0
worked, too.
|
|
|
|
|