dynamic calender

dynamic calender

hi i need the code to "insert date using GUI"

View Answers

November 19, 2010 at 2:36 PM

Hi Friend,

Try the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class DatePicker{
  int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
  int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);;
  JLabel l = new JLabel("",JLabel.CENTER);
  String day = "";
  JDialog d;
  JButton[] button = new JButton[49];
  public DatePicker(JFrame parent){
   d = new JDialog();
   d.setModal(true);
   String[] header = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};
   JPanel p1 = new JPanel(new GridLayout(7,7));
  p1.setPreferredSize(new Dimension(430,120));

   for(int x = 0; x < button.length; x++){
      final int selection = x;
      button[x] = new JButton();
      button[x].setFocusPainted(false);
      button[x].setBackground(Color.white);
      if(x>6)button[x].addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
        day = button[selection].getActionCommand();
        d.dispose();
        }});
      if(x < 7){
      button[x].setText(header[x]);
      button[x].setForeground(Color.red);
      }
       p1.add(button[x]);
    }
    JPanel p2 = new JPanel(new GridLayout(1,3));
    JButton previous = new JButton("<< Previous");
    previous.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
      month--;
      displayDate();}});
    p2.add(previous);
    p2.add(l);
    JButton next = new JButton("Next >>");
    next.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    month++;
    displayDate();
    }
    });
    p2.add(next);
    d.add(p1,BorderLayout.CENTER);
    d.add(p2,BorderLayout.SOUTH);
    d.pack();
    d.setLocationRelativeTo(parent);
    displayDate();
    d.setVisible(true);
   }
  public void displayDate(){
    for(int x = 7; x < button.length; x++) button[x].setText("");
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM yyyy");
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.set(year,month,1);
    int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
    int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
    for(int x = 6+dayOfWeek,day = 1; day <= daysInMonth; x++,day++) button[x].setText(""+day);
    l.setText(sdf.format(cal.getTime()));
   d.setTitle("Date Picker");
  }
  public String setPickedDate() {
   if(day.equals("")) return day;
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
      java.util.Calendar cal = java.util.Calendar.getInstance();
      cal.set(year,month,Integer.parseInt(day));
      return sdf.format(cal.getTime());
   }
  }
class Picker{
    public static void main(String[] args){
    JLabel label = new JLabel("Selected Date:");
    final JTextField text = new JTextField(20);
    JButton b = new JButton("popup");
    JPanel p = new JPanel();
    p.add(label);
    p.add(text);
    p.add(b);
    final JFrame f = new JFrame();
    f.getContentPane().add(p);
    f.pack();
    f.setVisible(true);
    b.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        text.setText(new DatePicker(f).setPickedDate());
      }
    });
   }
}

Thanks









Related Tutorials/Questions & Answers:
dynamic calender
dynamic calender  hi i need the code to "insert date using GUI"   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt.*; import java.awt.event.*; import javax.swing.*; class DatePicker{ int month
Calender in JSP
Calender in JSP  How can i use calender in my text box in JSP file
Advertisements
Calender in JSP
Calender in JSP  How can i use calender in my text box in JSP file
calender control
calender control  plz tell me about calender type control in java
calender event
calender event  hi, how we can set an alarm in calender through j2me and sending that reminder to another mobile? thanks in advance
how to use calender in php
how to use calender in php  how to put calender in php
Calender code
Calender code  how can i add 3 days to current date ? i am using a script from jotform which has a calender field. the system shows the current date, but i want to add 3 days to the current date for the purpose that the client
calender applet
calender applet  here is my code im getting errors in 23,37,49lines like cant find symbols constructor,methods e.tc is it the code for calender beside textfield in a java awt.... import java.applet.*; import java.awt.*; import
calender
Calender code
Calender code  hi, this is my script, where do i add your script below to? var Calendar = Class.create(); //------------------------------------------------------------------------------ // Constants
java awt calender
java awt calender  java awt code for calender to include beside a textfield
Calender Reminders - JSP-Servlet
Calender Reminders  HI All, I need to create calender reminder.I need java coding for that.It must appear like microsoft outlook..Please help me regard this as this is some what urgent for me..Thank you in advance..Waiting
calender devlopment - Java Beginners
calender devlopment  Sir i need help sir. Sir how to develop calender by using JAVA SWING. Here conditions are one textbox and one small button are needed for this application.whenever i click on small button small calender
calender working in struts - Struts
calender working in struts  when i execute the following code ,that is working properly if i convert to struts html tags that code is not working please help me to rectify the problem
calender in struts - Struts
calender in struts  when i execute the following code ,that is working properly if i convert to struts html tags that code is not working please help me to rectify the problem
Calender - JSP-Servlet
Calender  hi,i am designing a web portal in that my home page should display a calender. i want a calender to be displayed on my home page as jsp... i want is the calender with events showing the description on click Thanks
calender - JSP-Servlet
calender  i created a calender using java script but when i click the icon of the calendar it popups but when i again click the icon another popup opens without closing the previous one so i need the help to close it when i click
ModuleNotFoundError: No module named 'calender_merger'
ModuleNotFoundError: No module named 'calender_merger'  Hi, My... named 'calender_merger' How to remove the ModuleNotFoundError: No module named 'calender_merger' error? Thanks   Hi, In your python
Calender - JSP-Servlet
Calender  My answer was not that u posted... A calender should be dispalyed with the current month and every date should be clickable on click at particular date any event in the data base should be checked and display
Calender code ! HELP!!!
Calender code ! HELP!!!  how can i add 3 days to current date ? i am using a script from jotform which has a calender field. the system shows the current date, but i want to add 3 days to the current date for the purpose
need popup calender - Date Calendar
need popup calender  Hi, I need a pop up calender code in html, but i guess javascript would be needed for event handling . I need a code which.... The background and foreground color of the pop-calender should be able tochange Thanks
DYNAMIC BINDING
DYNAMIC BINDING  WHAT IS DYNAMIC BINDING
want the code for calender in php+htmal page
want the code for calender in php+htmal page   i have to select a calendra for some textbox in an table
dynamic report
dynamic report  i need complete code for generating dynamic report in jsp
dynamic polymorphism
dynamic polymorphism  Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism
Dynamic keyword
Dynamic keyword  hi....... What is the dynamic keyword used for in flex? give me the answer ASAP Thanks  Ans: Dynamic keyword-> Specifies that instances of a class may possess dynamic properties added
dynamic jquery statement
dynamic jquery statement  dynamic jquery statement
dynamic polymorphism
dynamic polymorphism  give an example for dynamic polymorphism?   Dynamic polymorphism is where a class overrides a superclass method... seen at runtime, so they are considered dynamic. Here is an example
how to prevent user selecting past date from calender
how to prevent user selecting past date from calender  how to prevent user selecting past date from calender ex: today's date is 21st march user should not select 20th march or below
PHP Dynamic CheckBox
PHP Dynamic CheckBox  Help with Dynamic Checkbox in PHP
php dynamic array checking
php dynamic array checking  php dynamic array checking
php dynamic array checking
php dynamic array checking  php dynamic array checking
create dynamic array in javascript
create dynamic array in javascript  How to create dynamic array in javascript
dynamic textfields
dynamic textfields  Hi, I am a fresher and joined recently in one company. they gave me a desktop application project using swings.here is my detailed spec Screen 1 - The user enters the ingredients from a food product, saves
Dynamic form
Dynamic form  I need to make a dynamic form using jsp for example, i will need a list of items which when we select one option another list is modified ( like 2 lists of countries and citys ), and also a radio button wich once
dynamic form
dynamic form  I need to make a dynamic form using php, for example, i will need a list of items which when we select one option another list is modified ( like 2 lists of countries and citys from a dtabase ), and also a radio
dynamic query
dynamic query  DECLARE QUERY VARCHAR2(32767); FIN_QUERY VARCHAR2(32767); CURSOR C IS (select distinct PORTFOLIO from MPE_TEST1); CURSOR C2 IS SELECT DISTINCT PORTFOLIO_LEVEL, PORTFOLIO FROM MPE_TEST1 ORDER
how to add dynamic data
how to add dynamic data  how to add dynamic data to an existing web application
dynamic web pages in html
dynamic web pages in html  How to create Dynamic web pages in HTML
static page and dynamic pages?
static page and dynamic pages?  what is the static page and dynamic pages
static page and dynamic pages?
static page and dynamic pages?  what is the diff between static page and dynamic pages
static page and dynamic pages?
static page and dynamic pages?  what is the static page and dynamic pages adv and disadv
Dynamic include jsp
Dynamic include jsp  I need dynamic include jsp page with an example
ModuleNotFoundError: No module named 'dynamic'
ModuleNotFoundError: No module named 'dynamic'  Hi, My Python... 'dynamic' How to remove the ModuleNotFoundError: No module named 'dynamic... to install padas library. You can install dynamic python with following command
ModuleNotFoundError: No module named 'dynamic'
ModuleNotFoundError: No module named 'dynamic'  Hi, My Python... 'dynamic' How to remove the ModuleNotFoundError: No module named 'dynamic... to install padas library. You can install dynamic python with following command
dynamic image change javascript
dynamic image change javascript  How to display images in JavaScript dynamically
Dynamic Array iPhone
Dynamic Array iPhone  Dynamic Array iPhone How can i add NSMutable array dynamically into my iPhone App
Dynamic polymorphism - Java Beginners
Dynamic polymorphism  Develop with suitable hierarchy, classes for point, shape, rectangele, square, circle,ellipse, triangle, polygon, etc. Design a simple test application to demonstrate dynamic polymorphism.. Thanks
Dynamic Polymorphism - Java Beginners
Dynamic Polymorphism  Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism.? Thanks
Dynamic html examples
Dynamic html examples  Hi, What is Dynamic HTML? Explain with dynamic html examples. Thanks (adsbygoogle = window.adsbygoogle || []).push({});   Hi, DHTML stands for Dynamic HTML and is uses the HTML

Ads