Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Date-Calendar this is my code java

Have Programming Question? Ask it here!
 
 
 


hendra
this is my code java
1 Answer(s)      5 years and 11 months ago
Posted in : Date-Calendar



Advertisement
View Answers

October 11, 2008 at 12:27 PM


use this code inside ur program

package rajanikant.code.oct_2008;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class SwingDate extends JFrame{

JTextField f1, f2;
JLabel l1,l2;
JPanel panel;
JButton calc = new JButton("Calculate");
public void calculate(){
Container container = getContentPane();
panel = new JPanel();
l1 = new JLabel("Date1");
f1 = new JTextField(15);
l2 = new JLabel("Date2");
f2 = new JTextField(15);
panel.add(l1);
panel.add(f1);
panel.add(l2);
panel.add(f2);
panel.add(calc);
container.add("Center", panel);
// setSize(new Dimension(50,50));
setVisible(true);
setSize(50, 100);
pack();

calc.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {
String date1 = f1.getText();
String date2 = f2.getText();
try {
getDiffer(date1, date2);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

});

}
public void getDiffer(String dt1, String dt2) throws ParseException{

Date date1;// = new Date();
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
date1 = sdf.parse(dt1);
calendar.setTime(date1);
int cur_month = calendar.get(Calendar.MONTH)+1;
int cur_year = calendar.get(Calendar.YEAR);
int cur_date = calendar.get(Calendar.DATE);
String df1 = cur_date + "-" + cur_month + "-" + cur_year;


Date date2;
// String newdate = "19-07-2006";
date2 = sdf.parse(dt2);
calendar.setTime(date2);
int month = calendar.get(Calendar.MONTH)+1;
int year = calendar.get(Calendar.YEAR);
int date = calendar.get(Calendar.DATE);

String df2 = date + "-" + month + "-"+ year;

int day = 0;
int no_of_days = 0;
int flag = 0;
if (cur_year % 4 == 0) {

if (cur_year % 100 != 0) {
flag = 1;
}
else if (cur_year % 400 == 0) {
flag = 1;
}
else {
flag = 0;
}
}
// It is not divisible by 4.
else {
flag = 0;
}
if(cur_month == 2){
if(flag == 1){
no_of_days = 29;
}else{
no_of_days = 28;
}
}


if(cur_month == 1 || cur_month == 3 || cur_month == 5 || cur_month == 7 || cur_month == 8 || cur_month == 10 || cur_month == 12){
no_of_days = 31;
}
if(cur_month == 4 || cur_month == 6 || cur_month == 9 || cur_month == 11){
no_of_days = 30;
}
if(cur_date > date){
day = cur_date - date;
}else{
day = cur_date - date + no_of_days;
cur_month = cur_month - 1;
}

if(cur_month > month){
cur_month = cur_month - month;
}else{
cur_month = cur_month - month + 12;
cur_year = cur_year - 1;
}
if(cur_year > year){
cur_year = cur_year - year;
}else{
cur_year = 0;
}
String diff = "Difference Between " + df1 + " and " + df2 + " is : " +cur_year + " Year " + cur_month + " Month " +day + " Days";
JOptionPane.showMessageDialog(this,diff);
}
public static void main(String s[]){
new SwingDate().calculate();
}
}

Rajanikant


Related Tutorials/Questions & Answers:
this is my code java - Date Calendar
this is my code java  /* * NewJFrame.java * * Created on 11... NOT modify this code. The content of this method is * always regenerated...; jTextField1.setText(months); #### This My problem jTextField2.setText(days
ERROR with my JAVA code - Java Beginners
ERROR with my JAVA code  The error came up in my main method... it wasnt there until i finished my actionListener coding so I dont know how to fix this....it is really stressing me out!! HELP!!! import java.awt.*; import
Advertisements
doubt in my program code - Java Beginners
doubt in my program code  i have developed a web browser with the help of standard widget toolkit(swt) and java. i creted some buttons such as GO... the code i developed i can send u to ur mail if u give ur mail id
anyone willing to look over my code? (java)
anyone willing to look over my code? (java)  package inorder.without.cheats; import java.util.Arrays; import javax.swing.JOptionPane; public class InOrderWithOutCheats { public static void main(String[] args
how can i simplify my java code
how can i simplify my java code  /* Create a program that prompts... Scanner (System.in); String pass=""; int c = 1; int code=0...=Integer.toString(f); String q=Integer.toString(g); String r=Integer.toString
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert this php code int java/JSP . if (isset($_POST['orders'])) { $orders...]); $array[] = $item[1]; } } I tried like this (see below JSP code
Please help me to modify my java code from php code
Modify Java code from PHP Code  i want to covert this php code int java/JSP. if (isset($_POST['orders'])) { $orders = explode('&', $_POST...]; } } I tried like this (see below JSP code) ... but this is not giving me
Need someone to check and modify my simple code - Java Beginners
Need someone to check and modify my simple code   How to write a class that contains Variables that hold hourly rate of pay, number of hours...); } }   Hi Friend, You can use following code: import
Solve my code
Solve my code  import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.io.*; public class ChangeDetails extends... is the mistake in this code! This is working only one record doesn't work
Problem in my code - Development process
Problem in my code  Plz go thru this code. I want to check login and pwd with database. Backend MsAccess , Table name : Reg , Dsn Name: JJ While executing code am getting 404 error User Name Password
Pls review my code - Struts
Pls review my code  Hello friends, this is my code in struts action class this page contains checkboxes and radiobuttons also. when i enter the submit it shows me blank page. can anybody solve my problem its urgent. help me
pls review my code - Struts
pls review my code  Hello friends, This is the code in struts. when i click on the submit button. It is showing the blank page. Pls respond soon its urgent. Thanks in advance. public class LOGINAction extends Action
pls review my code - Struts
pls review my code  When i click on the submit page i am getting a blank page Pls help me. thanks in advance. public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request
My name, java project
My name, java project  Write a class that displays your first name... displayLetterA() { code goes in here }, ...and my names hayley ... anyone... letter being displayed should have the lines of code needed to display
My name, java project
My name, java project  Write a class that displays your first name... displayLetterA() { code goes in here }, ...and my names hayley ... anyone... letter being displayed should have the lines of code needed to display
Java Program MY NAME
Java Program MY NAME   Write a class that displays your first name vertically down the screen where each letter uses up to 5 rows by 5 columns... should have the lines of code needed to display that letter in a method
My first Java Program
My first Java Program  I have been caught with a practical exam to do the following: Write a program that takes input from a user through... You may not "cut off" any words in the middle I can be able to code step 1
java not run on my pc
java not run on my pc  i have installed java in pc but when i run and compile any program the massage is display that 'javac' is not recognized as an internal or external command
Form Code To Dispay Webpages On My Site
Form Code To Dispay Webpages On My Site  I want to use a form input box to display different pages on my site depending on the code the user types into the box. example: Producer Code 1234 would bring up Producer 1 page
i want to find the byte code of a image file ... for my project..plz if anybody help me for java coding i will grateful..
i want to find the byte code of a image file ... for my project..plz if anybody help me for java coding i will grateful..   i want to convert a image file to its byte code format that help me for the pattern matching in my
Not sure whats wrong with my code HELP PLEASE?!?!
Not sure whats wrong with my code HELP PLEASE?!?!  I cant figure out what I am doing wrong in my code can anyone help me out??? Grades function computeGrade( ) { var hw, lab, midt, fin, avg; hw = parseFloat
Small Bug How to solve in my code
Small Bug How to solve in my code  String season=""; pst = con.prepareStatement("SELECT DISTINCT(Season) season FROM specialdates where Regid... +=rs.getString("season") + ","; } in above code seasons +=rs.getString("season
PLEASE HELP WITH MY JAVA
PLEASE HELP WITH MY JAVA  Hey my name is Gavin and im a student at school that takes IT. my teacher has gave me a problem and i can't figure it out please help!!!!!!!! it is a for-loop question: Display the first 5 multiples
What's wrong with my pagination code in JSP?
What's wrong with my pagination code in JSP?  Dear experts, I've tried the following codes which I have copied from Java Ranch forum and deleted.... Hope someone can advise me how to. Thanks! print("code sample"); <
Help With My Java Project?
Help With My Java Project?  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two-dimension array where
My Servlet code not working - Development process
My Servlet code not working  HHi, After executing servlet am getting blank screen. Am using weblogic server and Eclipse editor. But jsp is working fine. Steps(what i did ) 1)Created servlet (In eclipse) and export it (saved
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
if my database(oracle) connection failure means wat is the code to write in exception ?
if my database(oracle) connection failure means wat is the code to write in exception ?  if my database(oracle) connection failure means wat is the code to write in exception
clarify my question - Java Beginners
clarify my question  Dear Sirs/Expert, Thanks for writing back... the matching tutors to the parent. I was telling you that my degree... code: Enter ID: Parents IDNameContact NoLocationTutors IDNameContact
Help Me in My Java Work
Help Me in My Java Work  Can you help me please... Write a Java application, to be called GpaCalculator, which will return a grade point average (GPA) when given a range of decimal figures representing a selection of exam marks
details of my program - Java Beginners
details of my program  hi 1- allow the customer to order any thing... the customers... and about the last posted code it dis not run too... stupid alittle bit but this is my home work  import java.util.
to add on to my queries - Java Beginners
to add on to my queries   Dear Experts, Sorry but I am worried that I did not explain clearly so I am adding in the error message I get from Netbean IDE when I run that queries using the last solution provided. I'm puzzled
this is my code but i cant able to run it wt is the problem
this is my code but i cant able to run it wt is the problem  import java.io.*; class createthread { int thread=4,i; class thread1 extends createthread { public void run() { for(i=0;i
this is my code but i cant able to run it wt is the problem
this is my code but i cant able to run it wt is the problem  import java.io.*; class createthread { int thread=4,i; class thread1 extends createthread { public void run() { for(i=0;i
My Base Class is Changing every time in my code. How I can overcome this?
My Base Class is Changing every time in my code. How I can overcome this?  I have had the below question asked in interview, i'm curious to learn... to change Generator). So, as an example of the code public class GeneratorBase1
java code
java code  what is the code to turn off my pc through java program
I need add my java program with a picture.
I need add my java program with a picture.  Good evng Frnds Friends i created 1 jar file in my desktop. I need add this program with 1 picture... creating 1 picture. Later the program adding code with that picture.. Any 1 plz
this is my javascript code and i am not understanding the mistake in this,please help me?
this is my javascript code and i am not understanding the mistake in this,please help me?  <html> <h2>Form Validation</h2> <script language = "Javascript"> function checkEmail
java program for me to see who are on my server
java program for me to see who are on my server  Hello, Im a beginner in java, doing some tutorials and stuff. I wanna write a java program to put on my server where i wanna see if like 3 people are on my server PLUS that i want
are my declared varibles right - Java Beginners
are my declared varibles right  here is what i have so far juswt wondering if my varibles are correct. public class Bug { public Bug(int... information on java visit to : http://www.roseindia.net/java/ Thanks
send my personal id - Java Beginners
send my personal id  If u have any information then my personal id
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
What's wrong with my form? - Java Beginners
What's wrong with my form?  Dear expert, I'm having trouble with my enquiry form. Hope you can tell me where my mistake lies. Thanks. Here's my jsp code: Enquiries var objForm = new Object
Addition to my previous post - Java Beginners
Addition to my previous post  Addition to my previous question about the address book program. I need to have separate classes: CmdLineAddressBook.java AddressBook.java Contact.java Address.java Name.java
java code
java code  I am beginer in java my question is how can i fill data from mysql database to jcombobox using netbeans
can't read my xml file in java
_COMMENT> //nothing ... in this row and my some java codes...can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui
Hello Sir I Have problem with My Java Project - Java Beginners
Hello Sir I Have problem with My Java Project  Hello Sir I want Ur Mail Id To send U details and Project Source Code, plz Give Me Ur Mail Id
 

 

 

DMCA.com