continue java

continue java

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 Tutorials/Questions & Answers:
Java Continue
Java Continue refers to Continue statement in java, used for skipping the current iteration of Boolean expression. Java Continue is a form of expression used in Boolean expression. Sometimes Java Continue is used with break statement
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
Advertisements
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 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.ADS_TO_REPLACE_1 In java 7, Continue statement stops the current
Continue statement in java
Continue statement in java In this section we will discuss about continue statement in java. continue is one of the branching statement used in most of the programming languages like C,C++ and java etc. Sometime we need to skip some
Java - Continue statement in Java
Java - Continue statement in Java       Continue: The continue statement is used in many programming...:\chandan>javac Continue.java C:\chandan>java Continue chandan
Continue in java
iteration of the loop. Continue statement in Java successfully used in many... like : C:\chandan>javac Continue.java C:\chandan>java Continue... chandan Value of a : 0 Resource: Java - Continue statement in Java
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 ADS
There is insufficient memory for the Java Runtime Environment to continue.
There is insufficient memory for the Java Runtime Environment to continue.  Hi, I am getting error "There is insufficient memory for the Java...) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory
Implementing Continue Statement In Java
Implementing Continue Statement In Java  ... continue statement. First all of define class "Continue"...;java.io.*; class Continue{   public static void 
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
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
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
Continue Statement       The continue statement occurs only inside the iterator statements like while, do or for statements. The continue statement skips the current iteration
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
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
The continue statement The continue statement is used in many programming languages such as C
The continue statement The continue statement is used in many programming languages such as C. The continue statement The continue statement is used in many programming languages such as C, C++, java etc. Sometimes we do not need
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
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... by 5 Example 2 (Continue):ADS_TO_REPLACE_2 <html> <head> <
ModuleNotFoundError: No module named 'django-continue-reading'
ModuleNotFoundError: No module named 'django-continue-reading'  Hi...: No module named 'django-continue-reading' How to remove the ModuleNotFoundError: No module named 'django-continue-reading' error? Thanks   
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
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
Continue statement in jsp
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
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
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 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
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 Control Statement
Statement : Java support three types of jumping statement break, continue...Java Control Statement Control flow statement is a statement that is used... statement :  Java supports two selection statements, if and switch
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...: C:\javac>javac BreakDemo.java C:\javac>java
Branching Statements in java 7
Branching Statements in java 7 In this section, we will discuss about Branching Statements in java 7. This is one type of control flow statement. Branching..._TO_REPLACE_1 break statement continue statement return statement Break
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
MessengerFX
MessengerFX       Web-based version of MSN Messenger. The advantage is that you can continue to use MSN Messenger at work or college (where IM messengers might be blocked), but since
VoIP Blogs
VoIP Blogs          VoIP Blog and Podcast The guys at TMC have been awesome in their support and I know they will continue to dominate the VoIP blogosphere and IP
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 Break example
these loops Java provides keywords such as break and continue respectively....     Java Break continue Java has two... Java Break example      
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 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
Java Programming Code HELP
Java Programming Code HELP  Hi, sir/madam. I am new here and currently developing a program whereby it can read the Java source file..." )) { scanState = SCANNED_CLASS; continue
xml file reading using java
xml file and send that output to particular email address using java  ...)) continue; NodeList NameDOBCity = emp.getChildNodes... = NameDOBCity.item(j); if(isTextNode(node)) continue
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
java - Java Beginners
java   Search for .txt files in the specified folder 1. if file exist continue 2. else reset
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 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
Java application Help?
Java application Help?  Write an application that accepts a users password from the keyboard. When the entered password is less then six characters..., prompt the user to reenter the password and do not let the user continue until
Java or Jsp code - JSP-Servlet
Java or Jsp code  Hello Sir, How to create the code for the password recovery page(like forgot gmail password question and answer page)using... another question(like password recovery page)and continue to end
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

Ads