java date selector ..

Ads
 

java date selector ..

hey,,,, i am creating my java project...for that i implementing a car renting system and i had used combo boxes to get Ranting start day inputs..3 combo(sy,sm,sd) yyyy ,mm,dd and for returning day i need to get 3 combo inputs(ry,rm,rd)... so when i update starting day... others should be updated

public class Traval_guider extends javax.swing.JFrame { java.util.Calendar cal= java.util.Calendar.getInstance();

    int day = cal.get(Calendar.DATE);
    int month = cal.get(Calendar.MONTH) + 1;
    int year = cal.get(Calendar.YEAR);

/** Creates new form Traval_guider */
public Traval_guider(String name)   
{
    super("Amizing Destination Traval(pvt) LTD - "+name);
    initComponents();
    jLabel1.setText("Welcome "+name);




    for(int i=year;i<year+5;i++)
    {
                    sy.addItem(i);

    }
    for (int k = month; k < 13; k++)
    {
                    sm.addItem(k);


    }
    for(int j=day;j<32;j++)
    {
                    sd.addItem(j);

    }
    for(int i=(Integer) sy.getSelectedItem();i<(Integer)sy.getSelectedItem()+5;i++)
    {
        ey.addItem(i);
    }


}

//i add same codeings for all 3(sy,sm,sd) action

private void syActionPerformed(java.awt.event.ActionEvent evt) {
ey.removeAllItems(); em.removeAllItems(); ed.removeAllItems(); if((Integer)sy.getSelectedItem()>year) { for(int i=1;i<13;i++) { em.addItem(i); } for (int k = 1; k < 32; k++) { ed.addItem(k);

        }

    }
    else
    {  for (int k =(Integer)sm.getSelectedItem(); k < 13; k++)
        {
                    em.addItem(k);

        }

                if((Integer)sm.getSelectedItem()>month)
                {
                       for(int j=1;j<32;j++)
                     {
                        ed.addItem(j);

                     }
                }
                else
                {
                     for(int j=day+1;j<32;j++)
                    {
                         ed.addItem(j);

                    }
                }
    } // TODO add your handling code here:
}

//and am geting this error please help me Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at st.Travalguider.syActionPerformed(Travalguider.java:237) at st.Travalguider.access$000(Travalguider.java:22) at st.Travalguider$1.actionPerformed(Travalguider.java:137) at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1240) at javax.swing.JComboBox.contentsChanged(JComboBox.java:1311) at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:100) at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:88) at javax.swing.DefaultComboBoxModel.addElement(DefaultComboBoxModel.java:126) at javax.swing.JComboBox.addItem(JComboBox.java:696) at st.Travalguider.(Travalguider.java:58) at st.Travalguider$4.run(Travalguider.java:355) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

thanks

View Answers

April 11, 2012 at 3:47 PM

import java.sql.*;
import java.awt.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;

public class GetDate{
    static String months[]={"Month","Jan","Feb","Mar","App","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
    static int getMonth(String month){
    for(int i = 0; i<12; i++) {
      if(month == months[i])
          return i;
    }
    return 0;
    }
public static void main(String args[]){
GetDate get=new GetDate();
}
public GetDate(){
JFrame f = new JFrame();
f.getContentPane().setLayout(null);
final JComboBox day=new JComboBox();
final JComboBox month=new JComboBox();
final JComboBox year=new JComboBox();
JButton button= new JButton("Submit");
day.addItem("Day");
year.addItem("Year");
for(int i=1;i<=31;i++){
day.addItem(i);
}
day.setBounds(10,10,10,10);
for(int j=0;j<months.length;j++){
month.addItem(months[j]);
}
for(int k=1980;k<=2012;k++){
year.addItem(k);
}
day.setBounds(50,50,60,20);
month.setBounds(120,50,80,20);
year.setBounds(210,50,60,20);
button.setBounds(50,80,100,20);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Object ob1=day.getSelectedItem();
Object ob2=month.getSelectedItem();
Object ob3=year.getSelectedItem();
int d=Integer.parseInt(ob1.toString());
String mon=ob2.toString();
int m=getMonth(mon);
int y=Integer.parseInt(ob3.toString());
Calendar cal = GregorianCalendar.getInstance();
cal.set(y, m-1, d);  
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(cal.getTime()));
}
});
f.add(day);
f.add(month);
f.add(year);
f.add(button);
f.setVisible(true);
f.setSize(300,200);
}
}

August 27, 2012 at 1:44 AM

please can u help me creating a java code for below one..

1) create form to add event with "Title", "description", "venue", "event start date", "event end date" and number of attendees".

2) use date picker to choose date (event start date should be greaterthat or equals to today's date and and event end date should be greater that start date.

3) list all events in table view, create action for each event to "Apply" and "list attendees" 4) create form to apply for event take attendees deatils like" name, email id, some description". 5) store attendees list in attendee table as per event id. 6) hide apply action after " attendees" count is equals to "n".

Ads









Related Tutorials/Questions & Answers:
java date selector ..
java date selector ..  hey,,,, i am creating my java project...for that i implementing a car renting system and i had used combo boxes to get Ranting start day inputs..3 combo(sy,sm,sd) yyyy ,mm,dd and for returning day i need
Java Date
Java Date  Hi, What is the API for Date management in Java? How use the Java Date API for manipulating date object in Java? Provide some... of API for working with date and time objects in Java. You can also use third
Advertisements
How to compare date in Java?
How to compare date in Java?  Hi, How to compare date in Java? Thanks   Hi, Check this example Date Comparison. Thanks
Mysql Date To Java Date
Mysql Date To Java Date       Mysql Date To Java Date retrieve the records from Mysql and display the date in java. Understand with Example The Tutorial illustrate an example from
how to add date and change date in java - netbeans
how to add date and change date in java - netbeans  I need to code use to increase date How to get date after 30 days using netbeans
Parsing date in Java
Parsing date in Java  How can i parse the date in Java in a simple format..?   SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy
java format date
java format date  Hi, How can I format the date in the following...) { Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); String formattedDate=sdf.format(date
Date picker in Java Swing
Date picker in Java Swing  Hello Sir, Sir ,I am in need of Time Picker just like the Date picker available in java Swing. Kindly... link: Java Date Time Picker Example   Hello Sir, Thank
Java String To Date
Java String To Date In this section you will read about how to convert... be convert into java.util.Date. Java string to date convert explains the conversion of Java string written into the specified format to a Java date object
date and time in awt(java)
date and time in awt(java)  sir, do you have an example of date in awt java which can be view over a textfield.   Display time in JTextField import java.util.*; import javax.swing.*; import java.awt.event.*; public
Getting Computer Date in java
Getting Computer Date in java  Hi , I want to get the PC Date... but this.. String strDate = new Date(); I get this server error, "The type Date is ambiguous". I've also tried Date date = new Date(); ... but it get's the same error
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java... in Java? Thanks   Hi, Check the tutorial: Java program to get current date. Thanks   Hi, To get the current date and time in Java you can use
date picker componnt - Java Beginners
date picker componnt  sir i need code for date picker in java swing for my project sir please send me sir
How to calculate Date Difference in Java?
How to calculate Date Difference in Java?  Hi, I have two dates variable. How to calculate Date Difference in Java? Thanks   Hi, You can use the Calendar class for calculating the date difference in Java. Get data
Java Date Class
Java Date Class  Hi Friend, I need to have a code to get the days between specific dates. Such if I enter 19 September 2011 to 21 September 2011, the days would be saturday, sunday and monday, the code I gave simply get one day
Java current date - How to get current date in Java
In this section, you will learn about displaying current date and time in Java
How to convert date to string in Java?
How to convert date to string in Java?  Hello developers, I have java.util.Date object and it has to be converted to date format. How to convert date to string in Java? Thanks   Hi, To convert java.util.Date object
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
want a program for date picker by using java swings
want a program for date picker by using java swings  to write a program for the date picker by using java swings.any one please help me by providing the code to this java date picker by using the java swings.previously a program
Addintion in year fields of sql date in a java page
Addintion in year fields of sql date in a java page  In my database i have a field StartDate and EndDate Now entering date from my jsp..., HttpServletResponse response) throws ServletException, IOException { Date
convert date month and year into word using java
Java Date Month Format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
Date Format required to change in java
Date Format required to change in java  can we change the format of date like sql as per our requirements???If yes then please give the detail solution
convert date month and year into word using java
convert date month and year  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
convert date month and year Java  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Match Date format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Basic format for Date and Month  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Convert Date Format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Date Format in Jave  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Convert Date Month format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here

Ads