Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

ItemStateListener

Thread view: 
Anoniem - 29 Mar 2006 16:44 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.