this is my code java

this is my code java

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
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
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
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
I need help on my Java code.... please please help me out!?
I need help on my Java code.... please please help me out!?  Well my code is supposed to ask for an input file and then (ex: input.txt), read... in the file. Also it should be displayed on the screen. However my code doesn't display
ModuleNotFoundError: No module named 'my-first-code-in-python'
ModuleNotFoundError: No module named 'my-first-code-in-python'  Hi...: No module named 'my-first-code-in-python' How to remove the ModuleNotFoundError: No module named 'my-first-code-in-python' error? Thanks   
ModuleNotFoundError: No module named 'my-first-code-in-python'
ModuleNotFoundError: No module named 'my-first-code-in-python'  Hi...: No module named 'my-first-code-in-python' How to remove the ModuleNotFoundError: No module named 'my-first-code-in-python' error? Thanks   
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
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 ADS_TO_REPLACE_1 function computeGrade( ) { var hw, lab, midt, fin, avg; hw
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
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"); <
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
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
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
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
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
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
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
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
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
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
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
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
java code
java code  what is the code to turn off my pc through java program
java code
java code  I am beginer in java my question is how can i fill data from mysql database to jcombobox using netbeans
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
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
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
JAVA CODE
JAVA CODE  JAVA SOURCE CODE TO BLOCK A PARTICULAR WEB SITES(SOCIAL WEB SITE
java code
java code  write a java code to convert hindi to english using arrays
java code
java code  hi any one please tell me the java code to access any link i mean which method of which class is used to open any link in java program
java code
java code  need java code for chart or graph which compare the performance of aprior algorithm and coherent rule algorithm.plz any one help me out
java code
java code  write a java code for finding a string in partiular position in a delimited text file and replace the word with the values given by user and write the file in new location

Ads