hendra
continue java
2 Answer(s)      4 years and 8 months ago
Posted in : Date-Calendar

View Answers

October 11, 2008 at 11:26 AM


Hi friend,


Please give full details and source code where you having the problem.


Thanks

October 11, 2008 at 12:23 PM


Thanks for posting in correct language...........

use this code

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 Pages:
continue java - Date Calendar
continue java  How to make a subtract date from jframe like jtexfield, data can input into jtextfied ? and how to get year, yesterday a have a question about how to substract dd mm yyyy can in this subtract have a year.thank
continue java - Date Calendar
continue java  and how to subtract date(day month year) form jframe(jtextfiled). Thank's  Hi friend, Please give full details and source code where you having the problem. Thanks   Thanks for posting
Continue and break statement
Continue and break statement  How can we use Continue and break statement in java program?   The continue statement restart the current... is an example of break and continue statement. Example - public class ContinueBreak
Continue Statement
about Continue Statement click on the link http:/www.roseindia.net/java/beginners... Continue Statement       The continue statement occurs only inside the iterator statements like while
Continue Statement in java 7
Continue Statement in java 7 In this tutorial we will discuss about continue statement in java 7. Continue Statement : Sometimes you need to skip block... statement in loops. In java 7, Continue statement stops the current iteration
Java - Continue statement in Java
Java - Continue statement in Java       Continue: The continue statement is used in many programming...;java Continue chandan Value of a : 0 chandan Value of a : 0
Implementing Continue Statement In Java
Implementing Continue Statement In Java  ... continue statement. First all of define class "Continue"...*; class Continue{   public static void main(String
The continue statement The continue statement is used in many programming languages such as C
; C:\chandan>javac Continue.java C:\chandan>java Continue chandan...The continue statement The continue statement is used in many programming languages such as C. The continue statement The continue statement is used
Java Break continue
Java Break continue       Java has two keywords break and continue in its branching... control from the point where it is passed. Break and Continue in Java
What is the difference between a break statement and a continue statement?
What is the difference between a break statement and a continue statement?   Hi, What is the difference between a break statement and a continue statement? Thanks,   Hello, In Java programming language supports 3
How to use 'continue' keyword in jsp page ?
How to use 'continue' keyword in jsp page ?       This is detailed java code that shows how to use 'continue' keyword in jsp page. The continue statement skips
Java Compilation error and how to continue from this - Java Beginners
Java Compilation error and how to continue from this  Camford Cars Rental Pte Ltd requires a software system to manage its daily operations like renting and returning of vehicles,booking and cancelling bookings,checking
break and continue
break and continue  hi difference between break and continue
break and continue
break and continue   hi i am jane pls explain the difference between break and continue
PHP Continue
Continue Control Structure: Continue is another type of control structure... iteration, continue is used within looping structures (like for, foreach, while, do-while and switch case)to avoid rest of the code.  If we want to continue
JavaScript Break Continue Statement
JavaScript Break-Continue Statement: Generally we need to put the break... of the  program. On the other hand continue helps us to continue the flow... (Continue): <html> <head> <title>Write your title here <
C break continue example
C break continue example     ... with continue statement in C. The continue statement provides a convenient way... the execution of the loop. If the number is greater than 10, the continue
Loop in java
on the following link to know all about it. While Loop in Java Do-While Loop in Java For Loop in Java Break statement in java Continue statement in Java
continue of doubts in place ad - JSP-Servlet
continue of doubts in place ad  and when user clicks on confirm check box then only save or submit button should get displayed and when clicked on save everyting selected on place ad page should get saved in database .and when
Java Break keyword
Java Break keyword       Java programming involves loops that are widely used by programmers and for handling these loops Java provides keywords such as break and continue
Java Break loop
Java Break loop       Java contains its own Branching Category in which it has two keywords of opposite nature, break and continue respectively. In the following example break
SCJP Module-5 Question-14
; switch (i) { 6    case 3: 7    continue; 8...; Answer: (D) Explanation: continue cannot be used outside of a loop
Java Control Statements
Java Control Statements      ... statements (while, do-while and for) and branching statements (break, continue... if The if statement: To start with controlling statements in Java, lets have a recap over
Java statements
Java statements  What is the difference between a break statement and a continue statement
Java statements
Java statements   What is the difference between a break statement and a continue statement
break
; Sometimes we use Jumping Statements in Java. Using for, while and do-while.... Using jumping statements like break and continue it is easier to jump out of loops...;javac BreakDemo.java C:\javac>java BreakDemo 0
java - Java Beginners
java   Search for .txt files in the specified folder 1. if file exist continue 2. else reset
java
); if(isTextNode(emp)) continue; NodeList NameDOBCity...)) continue; System.out.print(node.getFirstChild
In Java..
In Java..  You should create an object of type Average. In a loop the user will enter a value. The tester class should then check to determine... method. The data should be read in a loop and continue until the user enters
java
Java count occurrence of a word  there is file called "story.txt",in a program we want to count occurrence of a word (example bangalore...) { if (last == i) continue; last = i
Java
(); frame.setVisible(true); } }  continue.. Details.java
a java program - Java Beginners
a java program  well sir, i just wanna ask you something regarding... or od but the profram should continue till the user wants...? what should I do...()); if (num %2==0) continue; System.out.println("this number is even :" +num
java - Java Beginners
java  I want to know a java program that using For Loop which... you like to continue y or n: y Enter a character: B * * * * * * * * * * * * * * * would you like to continue y or n: y
java - Java Beginners
java  I want to know a java program that using For Loop which...) * * * * * * * * * * * * * * * would you like to continue y or n: y Enter a character: B * * * * * * * * * * * * * * * would you like to continue y or n: y Enter
set java exe file as background - Java Beginners
set java exe file as background  hi frenz, i am begineer to java. in my application i have a one exe file. now i wanna the file... is closed then v don't continue that application.. can u tell me how java exe file set
core java - Java Beginners
to catch. The catch block resolve the exceptional condition and then continue... the following link: http://www.roseindia.net/java/exceptions/catching-and-handling
Java Programming - Java Beginners
Java Programming  how to make programme to make a star with for loop...("*"); } System.out.println(" "); } } System.out.print("would you like to Continue y or n:"); str...(); } } } ------------------------------------------------ Read for more information. http://www.roseindia.net/java/ Thanks
Java User Transaction - Java Beginners
Java User Transaction  Hi, I am trying to do file handling through... will continue with the commit. Any transactions that were in the Rollback Phase will continue with the rollback. Thanks
Print in a long paper - Java Beginners
Print in a long paper  how to print text in long paper?? each print text, printer stops. not continue until the paper print out. Thanks
Reply - Java Beginners
Reply  Hi Friends, Thanking for ur continue response I know your giving idea but can u send me the code of this problem just example for 20 data
Java GUI Program - Java Beginners
Java GUI Program  How is the following program supposed to be coded... decimal places. ? The application prompts the user to continue. ? When the user chooses not to continue, the application
java program - Java Beginners
java program  1.Write a program in java to input a sentence and find out how many palindromes are there in the sentence. 2. Write a program in java... = s.length()-1; while (low  continue............. 2)Count spaces
java array
java array  write a java method that takes an array of float values...++) { float num = array[i]; if(num==0)continue; for (int j = 0; j < array.length; j++) { if(i==j)continue
sontrol statement - Java Beginners
sontrol statement  hi to all, can anybody send me program in which "break" and "continue" is used simultaneously.? plz its urgent.  Hi...++) { if (i % 2 != 1) { continue
Java programming - Java Beginners
Java programming  The Problem Write a program that asks the user to enter two words. The program then prints out both words on one line. The words... should ask for the first word and continue to ask until a word of an acceptable
java Application to java Applet
java Application to java Applet  sorry Java master disturb again how can i modify below this Java application to applet because in swtich case i had... to continue next Process?( y/n ): "); String dec = input.next(); if (dec.equals("y
java RMI - Java Server Faces Questions
java RMI  hi In a distributed system using RMI how can i check for down servers.when a server becomes down/active some actions should take place.so monitoring for server status should continue all the time.pls tell me how to do
jsp - Java Beginners
---> > continue.. <---Select Table
java servlet - Java Beginners
java servlet  Hi Friends, I want to create a small web application using net Beans.My intention is to create a log in page,if the person... Successful   continue.. 3)register.html: New Page

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.