DATE problem

Suppose the date format 28-feb-2007 so what i want to do is when you type 28 -feb-2007 automatically comes

i am able to do it. But what the problem is i used textfield to store that once you store the date as

28-feb-2007 in the textfield i am not able to change the month/year again or may be date also i am not able to change

so please help me in this

thanks in advance

[403 byte] By [anup123a] at [2007-11-26 19:56:29]
# 1

Suppose the date format 28 -feb-2007 so what i want to do is when you type 28 (-feb-2007) automatically comes

i am able to do it. But what the problem is i used textfield to store that once you store the date as

28-feb-2007 in the textfield i am not able to change the month/year again or may be date also i am not able to change

so please help me in this

thanks in advance

anup123a at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
se - pa - ra - te fields !!!!one for the daya choice group (pop up look) for the montha choice group (pop up look) for the yearwhen user type the day, fill the two choiceGroupsexample of ui in wtk : UIDemos -> ChoiceGroup
suparenoa at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
hi supareno, I have tried to do wht u said but actually i am not gettin actually wht u mean plz help me its 2 much imp cause my project sub dates are ahead..
anup123a at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
show us the code that you tried to do the stuff (and use [url= http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips[/url] to post !!!)
suparenoa at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

Hi ,

Thanks for remembering me to use various quotes my code is

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import java.util.*;

import javax.microedition.lcdui.Canvas;

import javax.microedition.lcdui.Graphics;

public class DateType extends MIDlet implements CommandListener,Runnable,ItemCommandListener

{

private ChoiceGroup group,group1,group2;

private Display display;

private Form form;

//private Form mainForm;

private TextField dateField,monthField,yearField;

private StringItem mStringItem_3,mStringItem_2,mStringItem_1;

//private StringItem st1,st2;

private Command exit;

private Command ok;

private String[] dayArray = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};

private String[] month={"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};

private String[] year={"2007","2008","2009","2010"};

private static Image image = null;

private static Image image1 = null;

Canvas myCanvas;

Canvas myCanvas1;

private StringItem item;

public DateType()

{

form = new Form("");

try

{

image = Image.createImage("/_single8.png");

image1=Image.createImage("/status_bar1.gif");

}

catch(Exception e)

{

System.out.println(e);

}

/*mStringItem_1 = new StringItem("ABC", null, Item.BUTTON);

//mStringItem_1.setLayout(Item.LAYOUT_RIGHT | Item.LAYOUT_DEFAULT);

mStringItem_1.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

mStringItem_1.setPreferredSize(form.getWidth()/10,-1);

mStringItem_2 = new StringItem("CDE", null, Item.BUTTON);

//mStringItem_2.setLayout(Item.LAYOUT_CENTER | Item.LAYOUT_DEFAULT);

mStringItem_2.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

mStringItem_2.setPreferredSize(form.getWidth()/10,-1);

mStringItem_3 = new StringItem("EFG", null, Item.BUTTON);

//mStringItem_3.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_DEFAULT);

mStringItem_3.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

mStringItem_3.setPreferredSize(form.getWidth()/10,-1);*/

exit = new Command("Exit", Command.SCREEN, 1);

ok = new Command("Ok",Command.SCREEN,1);

ChoiceGroup group = new ChoiceGroup("Date",ChoiceGroup.POPUP);

for(int i=0;i<dayArray.length;i++)

{

group.append(dayArray[i],image);

}

group.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

group.setPreferredSize(form.getWidth()/3,-1);

ChoiceGroup group1 = new ChoiceGroup("",ChoiceGroup.POPUP);

for(int i=0;i<month.length;i++)

{

group1.append(month[i],null);

}

group1.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

group1.setPreferredSize(form.getWidth()/10,-1);

ChoiceGroup group2 = new ChoiceGroup("",ChoiceGroup.POPUP);

for(int i=0;i<year.length;i++)

{

group2.append(year[i],null);

}

group2.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

group2.setPreferredSize(form.getWidth()/10,-1);

/*form.append(mStringItem_1);

form.append(mStringItem_2);

form.append(mStringItem_3);*/

//form.append(image1);

form.append(group);

form.append(group1);

form.append(group2);

dateField = new TextField("Date","",2,TextField.ANY);

dateField.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

dateField.setPreferredSize(form.getWidth()/3,-1);

monthField = new TextField("/","",3,TextField.ANY);

monthField.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

monthField.setPreferredSize(form.getWidth()/3,-1);

yearField = new TextField("/","",4,TextField.ANY);

yearField.setLayout(Item.LAYOUT_2|Item.LAYOUT_LEFT);

yearField.setPreferredSize(form.getWidth()/3,-1);

form.append(dateField);

form.append(monthField);

form.append(yearField);

/*Form mainForm = new Form("Layout");

StringItem st1 = new StringItem("first","");

st1.setLayout(Item.LAYOUT_2|Item.LAYOUT_EXPAND);

st1.setPreferredSize(mainForm.getWidth()/3,-1);

StringItem st2 = new StringItem("second","");

st2.setLayout(Item.LAYOUT_2|Item.LAYOUT_EXPAND);

st2.setPreferredSize(mainForm.getWidth()/3,-1);

mainForm.append(st1);

mainForm.append(st2);*/

form.addCommand(ok);

form.addCommand(exit);

form.setCommandListener(this);

item = new StringItem("Button ", "Button", Item.BUTTON);

form.append(item);

item.setDefaultCommand(ok);

item.setItemCommandListener(this);

//form.setItemStateListener(this);

}

public void startApp()

{

display = Display.getDisplay(this);

display.setCurrent(form);

}

public void pauseApp() { }

public void destroyApp (boolean unconditional) { }

public void commandAction(Command c, Item item)

{

if(c==ok)

{

this.form.deleteAll();

MyCanvas myCanvas=new MyCanvas();

display.setCurrent(myCanvas);

new Thread(this).start();

}

}

>

anup123a at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

Please check this code not the one i had sent before

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import java.util.*;

public class PhoneCalendar extends MIDlet implements CommandListener, ItemStateListener

{

private Command exit;

private Display display;

Form form;

DateField date;

Date today;

TextField textfield;

TextField textfield1;

private String totalDate="";

private String totalValue="";;

private String yearValue="";

private String monthValue="";

private String value1="";

private String value2="";

private ChoiceGroup group;

public PhoneCalendar()

{

form = new Form("Calendar");

today = new Date();

totalValue=today.toString();

yearValue=totalValue.substring(24,28);

monthValue=totalValue.substring(4,7);

totalDate="-"+monthValue+"-"+yearValue;

ChoiceGroup group = new ChoiceGroup("You label",ChoiceGroup.POPUP);

group.append("Jan", null);

group.append("Feb", null);

exit = new Command("Exit", Command.SCREEN, 1);

textfield = new TextField("Start Date(dd-mm-yyyy)","",20,TextField.ANY);

textfield1 = new TextField("End Date(dd-mm-yyyy)","",20,TextField.ANY);

date = new DateField("Select date", DateField.DATE);

date.setDate(new java.util.Date());

form.append(date);

form.append(textfield);

form.append(textfield1);

form.append(group);

form.addCommand(exit);

form.setCommandListener(this);

form.setItemStateListener(this);

}

public void startApp()

{

display = Display.getDisplay(this);

display.setCurrent(form);

}

public void itemStateChanged(Item item)

{

if(item==textfield)

{

value1=textfield.getString();

if(value1.length()<2)

{

System.out.println(""+value1);

textfield.setString(value1);

}

else

{

textfield.setString(value1+totalDate);

}

}

if(item==textfield1)

{

value2=textfield1.getString();

if(value2.length()<2)

{

System.out.println(""+value2);

textfield1.setString(value2);

}

else

{

textfield1.setString(value2+totalDate);

}

}

}

public void pauseApp() { }

public void destroyApp (boolean unconditional) { }

public void commandAction (Command c, Displayable s)

{

if (c == exit)

{

destroyApp(false);

notifyDestroyed();

}

}

}

anup123a at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
hey wait a minute !!! why don't you use a DateField?
suparenoa at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8

actually what i want to do is suppose the date is 1-mar-2007

then when you type in textfield 1 then mar and 2007 comes automatically and we will be able to change the mar and 2007 also if posiible.

i am not gettin how to do it with datefield i have tried it out with datefield but not succeded.

anup123a at 2007-7-9 22:50:32 > top of Java-index,Java Mobility Forums,Java ME Technologies...