02 September 2013

Spring MVC hello world example (Spring 4.0 Release)...


Coming soon.... 

Coming soon.... 

01 June 2012

Read CSV file using Java.

Using this code read .csv file, it's required  following jar.
           javacsv.jar



import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;


public class ReadCsvFile {
                String[] strArray ;
                String  variable_1 =  "";
                String variable_2 =  "";
                String variable_2 =  "";
                String a3 = "";
                int number ;
                int count = 0;
                String CsvFilePath="";
                public void CsvFileParser(String CsvFile){
                                this.CsvFilePath = CsvFile;
                                String result="";                                               
                                try {
                                                CsvReader products = new CsvReader(CsvFilePath);                                      
                                                while(products.readRecord()){
                                                                count++;                                                                                                                                                                                                              result = products.getRawRecord();
                                                                strArray = result.split(",");
                                                                variable_1  = strArray[0].trim();
                                                                variable_2   = strArray[1].trim();
                                                                variable_3  = strArray[2].trim();
                                                               
                                               System.out.println("Variable 1 : "+variable_1);
                                               System.out.println("Variable 2 : "+variable_2);
                                               System.out.println("Variable 3 : "+variable_3);
                                                                }
                                                } catch (FileNotFoundException e) {                                                                                                                                                        e.printStackTrace();                                                       
                                                } catch (IOException e) {
                                                                e.printStackTrace();
                                                }
                }                             
                public static void main(String[] args) {
                                ReadCsvFile x = new ReadCsvFile();
                                String CsvFile = "C:/ License.csv";              //CSV file path
                                try {
                                                                x.CsvFileParser(CsvFile);                                                                                                              
                                                } catch (Exception e) {
                                                                e.printStackTrace();
                                                }
                 }
}
Using this code read .csv file, it's required  following jar.
           javacsv.jar



import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;


public class ReadCsvFile {
                String[] strArray ;
                String  variable_1 =  "";
                String variable_2 =  "";
                String variable_2 =  "";
                String a3 = "";
                int number ;
                int count = 0;
                String CsvFilePath="";
                public void CsvFileParser(String CsvFile){
                                this.CsvFilePath = CsvFile;
                                String result="";                                               
                                try {
                                                CsvReader products = new CsvReader(CsvFilePath);                                      
                                                while(products.readRecord()){
                                                                count++;                                                                                                                                                                                                              result = products.getRawRecord();
                                                                strArray = result.split(",");
                                                                variable_1  = strArray[0].trim();
                                                                variable_2   = strArray[1].trim();
                                                                variable_3  = strArray[2].trim();
                                                               
                                               System.out.println("Variable 1 : "+variable_1);
                                               System.out.println("Variable 2 : "+variable_2);
                                               System.out.println("Variable 3 : "+variable_3);
                                                                }
                                                } catch (FileNotFoundException e) {                                                                                                                                                        e.printStackTrace();                                                       
                                                } catch (IOException e) {
                                                                e.printStackTrace();
                                                }
                }                             
                public static void main(String[] args) {
                                ReadCsvFile x = new ReadCsvFile();
                                String CsvFile = "C:/ License.csv";              //CSV file path
                                try {
                                                                x.CsvFileParser(CsvFile);                                                                                                              
                                                } catch (Exception e) {
                                                                e.printStackTrace();
                                                }
                 }
}

07 May 2011

Upload and Retrieve image using JSP.


Upload and Retrieve image using JSP.
          
  Hello friends,  I am write this blog for those programmer are required a code for “how to upload and retrieve images (photos) from server using JSP.”

There is two jsp files are used in this project, and this project following libraries are required.   
     commons-fileupload.jar
        commons-fileupload-1.2.1.jar
        commons-io-1.4

this project done using NetBeans IDE 6.9.1 IDE. and jdk1.6.0_23

Screen:





Code:
upload_file_multipale.jsp

<%@ page contentType="text/html; charset=iso-8859-1" language="java" errorPage="" %> 
<%@ page import="java.util.List"%> 
<%@ page import="java.util.Iterator"%> 
<%@ page import="java.io.File"%> 
<%@ page import="org.apache.commons.fileupload.*"%> 
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%> 
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.io.FilenameUtils"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.lang.Exception"%>


<center>
            <table border="2">
            <tr><td><h1>Your files are uploading.....</h1></td></tr>
            <%
       
                 String itemName="";
                boolean isMultipart = ServletFileUpload.isMultipartContent(request);
                       
                 if (!isMultipart){
                         out.println("The Form is not Multipart!!!!!");
                 }
                else
                {
                         FileItemFactory  factory = new DiskFileItemFactory();
                         ServletFileUpload upload = new ServletFileUpload(factory);
                         List items = null;
                         try {
                                        items = upload.parseRequest(request);
                         } catch (FileUploadException  e) {
                                        out.println(e.toString());
                         }
                                                Iterator itr = items.iterator();
                                   
                                                while (itr.hasNext()) {
                                                            FileItem item = (FileItem) itr.next();
                                                            if (item.isFormField()){
                                                                         String name = item.getFieldName();
                                                                         String value = item.getString();
                                                            }
                                                            else {
                                                                        try {
                                                                                     itemName = item.getName();
                                                                                    itemName = FilenameUtils.getName(itemName);
                                                                                    //out.println(itemName);

    File savedFile = new File(config.getServletContext().getRealPath("/")+"uploadedFiles/"+itemName);
                       item.write(savedFile);
                       session.setAttribute("FileName",itemName);
                                                                                   
                                                                       } catch (Exception e) {
                                                                                                out.println(e.toString());
                                                                        }
                                                            }
                                                }
                                    }
                        
            response.sendRedirect("/FileUpload/upload_file_multipale_html.jsp");
   %>
    </table>
   </center>




upload_file_multipale_html.jsp

<%@page import="java.io.File"%>
<html>

 <head>
     <title>Multipale file upload by using apache.commons.fileupload</title>
</head>
<body>
 <form action="upload_file_multipale.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1">
   <center>
   <table border="2">
       <tr>
                   <td align="center"><b> Upload and Retrieve Image (Photo)by using apache.commons.fileupload in JSP &nbsp;</td>
       </tr>
       <tr>
           <td>&nbsp;</td>
       </tr>
       <tr>
           <td align="center">
                               Specify file:  <input name="file" type="file" id="file">
            </td>
        </tr>
         <tr>
                 <td>&nbsp;</td>
         </tr>
          <tr>
                <td align="center">
                <input type="submit" name="Submit" value="Submit files"/>
            </td>
             </tr>
         <tr>
             <td>&nbsp;</td>
         </tr>
          <tr>
             <td align="center">By Ajay Shilwant <br> Email: xijay.ss@gmail.com <br> My blog: ajayshilwant.blogspot.com</td>
          </tr>
    </table>
       <br><br><br>
    <table align="center" border="1">
           <td>
               <%
                   
                     String FileName = (String)session.getAttribute("FileName");
                     File savedFile = new File(config.getServletContext().getContextPath() +"/uploadedFiles/"+FileName  );
                   
                %>
                <img src="<%=savedFile %>" width="100" height="100">

           </td>
       </table>
   <center>
 </form>
 </body>
 </html>


This project is available at following links…
any problem, suggestion please send me, my email id  xijay.ss@gmail.com



Upload and Retrieve image using JSP.
          
  Hello friends,  I am write this blog for those programmer are required a code for “how to upload and retrieve images (photos) from server using JSP.”

There is two jsp files are used in this project, and this project following libraries are required.   
     commons-fileupload.jar
        commons-fileupload-1.2.1.jar
        commons-io-1.4

this project done using NetBeans IDE 6.9.1 IDE. and jdk1.6.0_23

Screen:





Code:
upload_file_multipale.jsp

<%@ page contentType="text/html; charset=iso-8859-1" language="java" errorPage="" %> 
<%@ page import="java.util.List"%> 
<%@ page import="java.util.Iterator"%> 
<%@ page import="java.io.File"%> 
<%@ page import="org.apache.commons.fileupload.*"%> 
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%> 
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.io.FilenameUtils"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.lang.Exception"%>


<center>
            <table border="2">
            <tr><td><h1>Your files are uploading.....</h1></td></tr>
            <%
       
                 String itemName="";
                boolean isMultipart = ServletFileUpload.isMultipartContent(request);
                       
                 if (!isMultipart){
                         out.println("The Form is not Multipart!!!!!");
                 }
                else
                {
                         FileItemFactory  factory = new DiskFileItemFactory();
                         ServletFileUpload upload = new ServletFileUpload(factory);
                         List items = null;
                         try {
                                        items = upload.parseRequest(request);
                         } catch (FileUploadException  e) {
                                        out.println(e.toString());
                         }
                                                Iterator itr = items.iterator();
                                   
                                                while (itr.hasNext()) {
                                                            FileItem item = (FileItem) itr.next();
                                                            if (item.isFormField()){
                                                                         String name = item.getFieldName();
                                                                         String value = item.getString();
                                                            }
                                                            else {
                                                                        try {
                                                                                     itemName = item.getName();
                                                                                    itemName = FilenameUtils.getName(itemName);
                                                                                    //out.println(itemName);

    File savedFile = new File(config.getServletContext().getRealPath("/")+"uploadedFiles/"+itemName);
                       item.write(savedFile);
                       session.setAttribute("FileName",itemName);
                                                                                   
                                                                       } catch (Exception e) {
                                                                                                out.println(e.toString());
                                                                        }
                                                            }
                                                }
                                    }
                        
            response.sendRedirect("/FileUpload/upload_file_multipale_html.jsp");
   %>
    </table>
   </center>




upload_file_multipale_html.jsp

<%@page import="java.io.File"%>
<html>

 <head>
     <title>Multipale file upload by using apache.commons.fileupload</title>
</head>
<body>
 <form action="upload_file_multipale.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1">
   <center>
   <table border="2">
       <tr>
                   <td align="center"><b> Upload and Retrieve Image (Photo)by using apache.commons.fileupload in JSP &nbsp;</td>
       </tr>
       <tr>
           <td>&nbsp;</td>
       </tr>
       <tr>
           <td align="center">
                               Specify file:  <input name="file" type="file" id="file">
            </td>
        </tr>
         <tr>
                 <td>&nbsp;</td>
         </tr>
          <tr>
                <td align="center">
                <input type="submit" name="Submit" value="Submit files"/>
            </td>
             </tr>
         <tr>
             <td>&nbsp;</td>
         </tr>
          <tr>
             <td align="center">By Ajay Shilwant <br> Email: xijay.ss@gmail.com <br> My blog: ajayshilwant.blogspot.com</td>
          </tr>
    </table>
       <br><br><br>
    <table align="center" border="1">
           <td>
               <%
                   
                     String FileName = (String)session.getAttribute("FileName");
                     File savedFile = new File(config.getServletContext().getContextPath() +"/uploadedFiles/"+FileName  );
                   
                %>
                <img src="<%=savedFile %>" width="100" height="100">

           </td>
       </table>
   <center>
 </form>
 </body>
 </html>


This project is available at following links…
any problem, suggestion please send me, my email id  xijay.ss@gmail.com


03 May 2011

Send mail using Jsp and Servlet.

hello firends,

using this blog you can send mail using JSP and Servlets, follow the following steps to design this application


Send mail using Jsp and Servlet.
  1.    Create new web project using netbean. 
  2.       For this project following 5 labraries are requered.
a.       activation.jar
b.      mail.jar
c.       mailapi.jar
d.      pop3.jar
e.      smtp.jar
3.       After adding this library in project bellow code is copy and paste in index.jsp file.

index.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Java Mail</title>
    </head>
    <body>
        <form action="sendMail.jsp" method="POST">
            <table border="0" align="center" cellpadding="5">
                <tbody>
                    <thead><tr> <td colspan="3" align="center">
                    <b> Send Mail </b> </td> </tr> </thead>
                    <tr>
                        <td> To </td> <td> : </td>
                        <td> <input type="text" name="to" value="" /> </td>
                    </tr>
                    <tr>
                        <td> Subject </td> <td> : </td>
                        <td> <input type="text" name="subject" value="" /> </td>
                    </tr>
                    <tr>
                        <td> Message </td> <td> : </td>
                        <td> <textarea name="message" rows="8" cols="30">
                        </textarea></td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">
                        <input type="submit" value="Send Mail" />

                        <input type="reset" value="Reset" />
                        <td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>


Screen of index.jsp


sendMail.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Send Mail</title>
    </head>
    <body>
        <jsp:useBean id="mail" scope="session" class="jMail.Mail" />
        <jsp:setProperty name="mail" property="to" param="to" />
        <jsp:setProperty name="mail" property="from"  value="smaple@gmail.com" />

                <!-- Note:  value = add your email id hear -->

        <jsp:setProperty name="mail" property="smtpServ" value="smtp.gmail.com" />
        <jsp:setProperty name="mail" property="subject" param="subject" />
        <jsp:setProperty name="mail" property="message" param="message" />

        <%
String to = mail.getTo();
int result;
result = mail.sendMail();
if(result == 0){
    out.println(" Mail Successfully Sent to "+to);
}
else{
    out.println(" Mail NOT Sent to "+to);
}
       %>
    </body>
</html>






Java File: 

Mail.java


package jMail;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class Mail {
    private String to;
    private String from;
    private String message;
    private String subject;
    private String smtpServ;


    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }
    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getSmtpServ() {
        return smtpServ;
    }
    public void setSmtpServ(String smtpServ) {
        this.smtpServ = smtpServ;
    }

public int sendMail(){
        try
        {
            Properties props = System.getProperties();
              // -- Attaching to default Session, or we could start a new one --
              props.put("mail.transport.protocol", "smtp" );
              props.put("mail.smtp.starttls.enable","true" );
              props.put("mail.smtp.host",smtpServ);
              props.put("mail.smtp.auth", "true" );
              Authenticator auth = new SMTPAuthenticator();
              Session session = Session.getInstance(props, auth);
              // -- Create a new message --
              Message msg = new MimeMessage(session);
              // -- Set the FROM and TO fields --
              msg.setFrom(new InternetAddress(from));
              msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
              msg.setSubject(subject);
              msg.setText(message);
              // -- Set some other header information --
              msg.setHeader("MyMail", "Mr. XYZ" );
              msg.setSentDate(new Date());
              // -- Send the message --
              Transport.send(msg);
              System.out.println("Message sent to"+to+" OK." );
              return 0;
        }
        catch (Exception ex)
        {
          ex.printStackTrace();
          System.out.println("Exception "+ex);
          return -1;
        }
  }

// Also include an inner class that is used for authentication purposes

private class SMTPAuthenticator extends javax.mail.Authenticator {
        @Override
  public PasswordAuthentication getPasswordAuthentication() {
         String username =  "sender@gmail.com";           // specify your email id here (sender's email id)
         String password = "password";                             // specify your password here
        return new PasswordAuthentication(username, password);
     }
  }
}




After complete the coding run the project.
                If any problem face then contact me at  “ xijay.ss@gmail.com “ and this project is also available at  www.project –source-code.com download and use.




hello firends,

using this blog you can send mail using JSP and Servlets, follow the following steps to design this application


Send mail using Jsp and Servlet.
  1.    Create new web project using netbean. 
  2.       For this project following 5 labraries are requered.
a.       activation.jar
b.      mail.jar
c.       mailapi.jar
d.      pop3.jar
e.      smtp.jar
3.       After adding this library in project bellow code is copy and paste in index.jsp file.

index.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Java Mail</title>
    </head>
    <body>
        <form action="sendMail.jsp" method="POST">
            <table border="0" align="center" cellpadding="5">
                <tbody>
                    <thead><tr> <td colspan="3" align="center">
                    <b> Send Mail </b> </td> </tr> </thead>
                    <tr>
                        <td> To </td> <td> : </td>
                        <td> <input type="text" name="to" value="" /> </td>
                    </tr>
                    <tr>
                        <td> Subject </td> <td> : </td>
                        <td> <input type="text" name="subject" value="" /> </td>
                    </tr>
                    <tr>
                        <td> Message </td> <td> : </td>
                        <td> <textarea name="message" rows="8" cols="30">
                        </textarea></td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">
                        <input type="submit" value="Send Mail" />

                        <input type="reset" value="Reset" />
                        <td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>


Screen of index.jsp


sendMail.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Send Mail</title>
    </head>
    <body>
        <jsp:useBean id="mail" scope="session" class="jMail.Mail" />
        <jsp:setProperty name="mail" property="to" param="to" />
        <jsp:setProperty name="mail" property="from"  value="smaple@gmail.com" />

                <!-- Note:  value = add your email id hear -->

        <jsp:setProperty name="mail" property="smtpServ" value="smtp.gmail.com" />
        <jsp:setProperty name="mail" property="subject" param="subject" />
        <jsp:setProperty name="mail" property="message" param="message" />

        <%
String to = mail.getTo();
int result;
result = mail.sendMail();
if(result == 0){
    out.println(" Mail Successfully Sent to "+to);
}
else{
    out.println(" Mail NOT Sent to "+to);
}
       %>
    </body>
</html>






Java File: 

Mail.java


package jMail;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class Mail {
    private String to;
    private String from;
    private String message;
    private String subject;
    private String smtpServ;


    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }
    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getSmtpServ() {
        return smtpServ;
    }
    public void setSmtpServ(String smtpServ) {
        this.smtpServ = smtpServ;
    }

public int sendMail(){
        try
        {
            Properties props = System.getProperties();
              // -- Attaching to default Session, or we could start a new one --
              props.put("mail.transport.protocol", "smtp" );
              props.put("mail.smtp.starttls.enable","true" );
              props.put("mail.smtp.host",smtpServ);
              props.put("mail.smtp.auth", "true" );
              Authenticator auth = new SMTPAuthenticator();
              Session session = Session.getInstance(props, auth);
              // -- Create a new message --
              Message msg = new MimeMessage(session);
              // -- Set the FROM and TO fields --
              msg.setFrom(new InternetAddress(from));
              msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
              msg.setSubject(subject);
              msg.setText(message);
              // -- Set some other header information --
              msg.setHeader("MyMail", "Mr. XYZ" );
              msg.setSentDate(new Date());
              // -- Send the message --
              Transport.send(msg);
              System.out.println("Message sent to"+to+" OK." );
              return 0;
        }
        catch (Exception ex)
        {
          ex.printStackTrace();
          System.out.println("Exception "+ex);
          return -1;
        }
  }

// Also include an inner class that is used for authentication purposes

private class SMTPAuthenticator extends javax.mail.Authenticator {
        @Override
  public PasswordAuthentication getPasswordAuthentication() {
         String username =  "sender@gmail.com";           // specify your email id here (sender's email id)
         String password = "password";                             // specify your password here
        return new PasswordAuthentication(username, password);
     }
  }
}




After complete the coding run the project.
                If any problem face then contact me at  “ xijay.ss@gmail.com “ and this project is also available at  www.project –source-code.com download and use.




04 March 2011

Convert Number to String

Convert Number to String in Java using Swing..... (Editor use: Net Bean)





firstly create new project. in this project add one Java class file and name this file "EnglishNumberToWords.Java"
 and copy following line of code in this file.....

*************************Code********************************



package number;
import java.text.DecimalFormat;

public class EnglishNumberToWords {

  private static final String[] tensNames = {
    "",
    " ten",
    " twenty",
    " thirty",
    " forty",
    " fifty",
    " sixty",
    " seventy",
    " eighty",
    " ninety"
  };

  private static final String[] numNames = {
    "",
    " one",
    " two",
    " three",
    " four",
    " five",
    " six",
    " seven",
    " eight",
    " nine",
    " ten",
    " eleven",
    " twelve",
    " thirteen",
    " fourteen",
    " fifteen",
    " sixteen",
    " seventeen",
    " eighteen",
    " nineteen"
  };

  private static String convertLessThanOneThousand(int number) {
    String soFar;

    if (number % 100 < 20){
      soFar = numNames[number % 100];
      number /= 100;
    }
    else {
      soFar = numNames[number % 10];
      number /= 10;

      soFar = tensNames[number % 10] + soFar;
      number /= 10;
    }
    if (number == 0) return soFar;
    return numNames[number] + " hundred" + soFar;
  }


  public static String convert(long number) {
    // 0 to 999 999 999 999
    if (number == 0) { return "zero"; }

    String snumber = Long.toString(number);
   String snumber1 = Long.toString(number);
    // pad with "0"
    String mask = "000000000000";
    String mask1 =  "000000000";
    DecimalFormat df = new DecimalFormat(mask);
    DecimalFormat df1 = new DecimalFormat(mask1);

    snumber = df.format(number);
    snumber1 = df1.format(number);
  
    // XXXnnnnnnnnn
    int billions = Integer.parseInt(snumber.substring(0,3));
    int coror = Integer.parseInt(snumber1.substring(0, 2));

    // nnnXXXnnnnnn
    int millions  = Integer.parseInt(snumber.substring(3,6));
    int lakh = Integer.parseInt(snumber1.substring(2,4));
    int thousand = Integer.parseInt(snumber1.substring(4,6));
    int hundred = Integer.parseInt(snumber1.substring(6,9));
    //System.out.println("---1---"+coror+"-------2--------"+lakh+"-----3--------"+thousand+"-------4-------"+hundred);
    String corors;
    switch(coror){
         case 0:
             corors = "";
             break;
        case 1:
            corors = convertLessThanOneThousand(coror)+" corror";
            break;
         default:
            corors = convertLessThanOneThousand(coror)+" corror";
      
    }
    String result1 =  corors;
    String lakhs;
    switch(lakh){
        case 0 :
            lakhs = "";
            break;
        case 1  :
            lakhs = convertLessThanOneThousand(lakh)+" lakh";
            break;
            default:
                lakhs = convertLessThanOneThousand(lakh)+" lakh";
              
    }
    result1 = result1+lakhs;
    String thou;
    switch(thousand){
        case 0 :
            thou = "";
            break;
        case 1:
            thou =lakhs = convertLessThanOneThousand(thousand)+" thausands";
            break;
            default:
                thou =lakhs = convertLessThanOneThousand(thousand)+" thausands";
    }
    result1 = result1+thou;
    result1 = result1+convertLessThanOneThousand(hundred);

    // nnnnnnXXXnnn
    int hundredThousands = Integer.parseInt(snumber.substring(6,9));
    // nnnnnnnnnXXX
    int thousands = Integer.parseInt(snumber.substring(9,12));  

    String tradBillions;
    switch (billions) {
    case 0:
      tradBillions = "";
      break;
    case 1 :
      tradBillions = convertLessThanOneThousand(billions)
      + " billlions ";
      break;
    default :
      tradBillions = convertLessThanOneThousand(billions)
      + " Billions ";
    }
    String result =  tradBillions;

    String tradMillions;
    switch (millions) {
    case 0:
      tradMillions = "";
      break;
    case 1 :
      tradMillions = convertLessThanOneThousand(millions)
      + " million ";
      break;
    default :
      tradMillions = convertLessThanOneThousand(millions)
      + " million ";
    }
    result =  result + tradMillions;

    String tradHundredThousands;
    switch (hundredThousands) {
    case 0:
      tradHundredThousands = "";
      break;
    case 1 :
      tradHundredThousands = "one thousand ";
      break;
    default :
      tradHundredThousands = convertLessThanOneThousand(hundredThousands)
      + " thousand ";
    }
    result =  result + tradHundredThousands;

    String tradThousand;
    tradThousand = convertLessThanOneThousand(thousands);
    result =  result + tradThousand;

    // remove extra spaces!
    return result1.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ");
  }

  /**
   * testing
   * @param args
   */
  public static void main(String[] args) {
      System.out.println("my one"+EnglishNumberToWords.convert(237898555));
    System.out.println("*** " + EnglishNumberToWords.convert(0));
    System.out.println("*** " + EnglishNumberToWords.convert(1));
    System.out.println("*** " + EnglishNumberToWords.convert(16));
    System.out.println("*** " + EnglishNumberToWords.convert(100));
    System.out.println("*** " + EnglishNumberToWords.convert(118));
    System.out.println("*** " + EnglishNumberToWords.convert(200));
    System.out.println("***219 " + EnglishNumberToWords.convert(219));
    System.out.println("*** " + EnglishNumberToWords.convert(800));
    System.out.println("*** " + EnglishNumberToWords.convert(801));
    System.out.println("*** " + EnglishNumberToWords.convert(1316));
    System.out.println("*** " + EnglishNumberToWords.convert(1000000));
    System.out.println("*** " + EnglishNumberToWords.convert(2000000));
    System.out.println("*** " + EnglishNumberToWords.convert(3000200));
    System.out.println("*** " + EnglishNumberToWords.convert(700000));
    System.out.println("*** " + EnglishNumberToWords.convert(9000000));
    System.out.println("*** " + EnglishNumberToWords.convert(9001000));
    System.out.println("*** " + EnglishNumberToWords.convert(123456789));
    System.out.println("*** " + EnglishNumberToWords.convert(2147483647));
    System.out.println("*** " + EnglishNumberToWords.convert(3000000010L));
}
}


****************************************************************


after that create one Java Frame with one Text Box, one Button and labels, design same like as above image

after that at Button Click Event (ActionPerformed event) add following code.....


*************************Code***********************************

 int Number = Integer.parseInt(txtNumber.getText());
        String No2String = EnglishNumberToWords.convert(Number)+"";
        txtString.setText(No2String);

in this code assign text box value to a "Number" variable and pass this value to the Function in above code "EnglishNumberToWords.Convert(Number)" and after that print the value

***************************Thanks************************************
Note : this project is available at  http://www.planet-source-code.com site

Convert Number to String in Java using Swing..... (Editor use: Net Bean)





firstly create new project. in this project add one Java class file and name this file "EnglishNumberToWords.Java"
 and copy following line of code in this file.....

*************************Code********************************



package number;
import java.text.DecimalFormat;

public class EnglishNumberToWords {

  private static final String[] tensNames = {
    "",
    " ten",
    " twenty",
    " thirty",
    " forty",
    " fifty",
    " sixty",
    " seventy",
    " eighty",
    " ninety"
  };

  private static final String[] numNames = {
    "",
    " one",
    " two",
    " three",
    " four",
    " five",
    " six",
    " seven",
    " eight",
    " nine",
    " ten",
    " eleven",
    " twelve",
    " thirteen",
    " fourteen",
    " fifteen",
    " sixteen",
    " seventeen",
    " eighteen",
    " nineteen"
  };

  private static String convertLessThanOneThousand(int number) {
    String soFar;

    if (number % 100 < 20){
      soFar = numNames[number % 100];
      number /= 100;
    }
    else {
      soFar = numNames[number % 10];
      number /= 10;

      soFar = tensNames[number % 10] + soFar;
      number /= 10;
    }
    if (number == 0) return soFar;
    return numNames[number] + " hundred" + soFar;
  }


  public static String convert(long number) {
    // 0 to 999 999 999 999
    if (number == 0) { return "zero"; }

    String snumber = Long.toString(number);
   String snumber1 = Long.toString(number);
    // pad with "0"
    String mask = "000000000000";
    String mask1 =  "000000000";
    DecimalFormat df = new DecimalFormat(mask);
    DecimalFormat df1 = new DecimalFormat(mask1);

    snumber = df.format(number);
    snumber1 = df1.format(number);
  
    // XXXnnnnnnnnn
    int billions = Integer.parseInt(snumber.substring(0,3));
    int coror = Integer.parseInt(snumber1.substring(0, 2));

    // nnnXXXnnnnnn
    int millions  = Integer.parseInt(snumber.substring(3,6));
    int lakh = Integer.parseInt(snumber1.substring(2,4));
    int thousand = Integer.parseInt(snumber1.substring(4,6));
    int hundred = Integer.parseInt(snumber1.substring(6,9));
    //System.out.println("---1---"+coror+"-------2--------"+lakh+"-----3--------"+thousand+"-------4-------"+hundred);
    String corors;
    switch(coror){
         case 0:
             corors = "";
             break;
        case 1:
            corors = convertLessThanOneThousand(coror)+" corror";
            break;
         default:
            corors = convertLessThanOneThousand(coror)+" corror";
      
    }
    String result1 =  corors;
    String lakhs;
    switch(lakh){
        case 0 :
            lakhs = "";
            break;
        case 1  :
            lakhs = convertLessThanOneThousand(lakh)+" lakh";
            break;
            default:
                lakhs = convertLessThanOneThousand(lakh)+" lakh";
              
    }
    result1 = result1+lakhs;
    String thou;
    switch(thousand){
        case 0 :
            thou = "";
            break;
        case 1:
            thou =lakhs = convertLessThanOneThousand(thousand)+" thausands";
            break;
            default:
                thou =lakhs = convertLessThanOneThousand(thousand)+" thausands";
    }
    result1 = result1+thou;
    result1 = result1+convertLessThanOneThousand(hundred);

    // nnnnnnXXXnnn
    int hundredThousands = Integer.parseInt(snumber.substring(6,9));
    // nnnnnnnnnXXX
    int thousands = Integer.parseInt(snumber.substring(9,12));  

    String tradBillions;
    switch (billions) {
    case 0:
      tradBillions = "";
      break;
    case 1 :
      tradBillions = convertLessThanOneThousand(billions)
      + " billlions ";
      break;
    default :
      tradBillions = convertLessThanOneThousand(billions)
      + " Billions ";
    }
    String result =  tradBillions;

    String tradMillions;
    switch (millions) {
    case 0:
      tradMillions = "";
      break;
    case 1 :
      tradMillions = convertLessThanOneThousand(millions)
      + " million ";
      break;
    default :
      tradMillions = convertLessThanOneThousand(millions)
      + " million ";
    }
    result =  result + tradMillions;

    String tradHundredThousands;
    switch (hundredThousands) {
    case 0:
      tradHundredThousands = "";
      break;
    case 1 :
      tradHundredThousands = "one thousand ";
      break;
    default :
      tradHundredThousands = convertLessThanOneThousand(hundredThousands)
      + " thousand ";
    }
    result =  result + tradHundredThousands;

    String tradThousand;
    tradThousand = convertLessThanOneThousand(thousands);
    result =  result + tradThousand;

    // remove extra spaces!
    return result1.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ");
  }

  /**
   * testing
   * @param args
   */
  public static void main(String[] args) {
      System.out.println("my one"+EnglishNumberToWords.convert(237898555));
    System.out.println("*** " + EnglishNumberToWords.convert(0));
    System.out.println("*** " + EnglishNumberToWords.convert(1));
    System.out.println("*** " + EnglishNumberToWords.convert(16));
    System.out.println("*** " + EnglishNumberToWords.convert(100));
    System.out.println("*** " + EnglishNumberToWords.convert(118));
    System.out.println("*** " + EnglishNumberToWords.convert(200));
    System.out.println("***219 " + EnglishNumberToWords.convert(219));
    System.out.println("*** " + EnglishNumberToWords.convert(800));
    System.out.println("*** " + EnglishNumberToWords.convert(801));
    System.out.println("*** " + EnglishNumberToWords.convert(1316));
    System.out.println("*** " + EnglishNumberToWords.convert(1000000));
    System.out.println("*** " + EnglishNumberToWords.convert(2000000));
    System.out.println("*** " + EnglishNumberToWords.convert(3000200));
    System.out.println("*** " + EnglishNumberToWords.convert(700000));
    System.out.println("*** " + EnglishNumberToWords.convert(9000000));
    System.out.println("*** " + EnglishNumberToWords.convert(9001000));
    System.out.println("*** " + EnglishNumberToWords.convert(123456789));
    System.out.println("*** " + EnglishNumberToWords.convert(2147483647));
    System.out.println("*** " + EnglishNumberToWords.convert(3000000010L));
}
}


****************************************************************


after that create one Java Frame with one Text Box, one Button and labels, design same like as above image

after that at Button Click Event (ActionPerformed event) add following code.....


*************************Code***********************************

 int Number = Integer.parseInt(txtNumber.getText());
        String No2String = EnglishNumberToWords.convert(Number)+"";
        txtString.setText(No2String);

in this code assign text box value to a "Number" variable and pass this value to the Function in above code "EnglishNumberToWords.Convert(Number)" and after that print the value

***************************Thanks************************************
Note : this project is available at  http://www.planet-source-code.com site