String paging code

  Abstract: string paging code 

  </ Td> </ tr> <tr> <td width="527" height="35" valign="top" class="ArticleTeitle"> use examples: 
  StringPager pager = new StringPager (); 
  Pager.setSizePerPage (5); / / characters per page 
  Pager.setText ( "12345678901 ");// need a long text paging 
  Pager.setCurrentPage (2); / / Current Page 

  System.out.println (pager.getTotalPage ());// total number of pages 
  System.out.println (pager.getCurrentPagedText pages of the current string ());// 

  Note: Java-based concept of the length of the string, each page is displayed in English and Chinese, as are the length of a page. 
  All source documents: 


  Package examples; 
  / * 
  * @ (#) StringPager.java 1.00 2004-10-10 
*
  * Copyright 2004 All rights reserved. 
  * PROPRIETARY / CONFIDENTIAL. Use is subject to license terms. 
  * / 


  / ** 
  * StringPager, string tabs. 
*
  * @ Author Liuchangjiong 
  * @ Version 1.00 2004-10-10 
  * / 
  (Public class StringPager 

  / ** Current page number * / 
  Private int currentPage = 1; 

  / ** Paging needs of the long string * / 
  Private String text; 

  / ** Characters per page, the default is 200 * / 
  Private int sizePerPage = 200; 

  / ** Total number of pages * / 
  Private int totalPage; 


  Public StringPager () () 

  / ** 
  * Return to the pages of string. 
  * @ Return 
  * / 
  Public String getCurrentPagedText () ( 
  Try ( 
  If (getCurrentPage () <getTotalPage ()) ( 
  Return getText (). Substring ((getCurrentPage () - 1) * getSizePerPage (), 
  GetCurrentPage () * getSizePerPage ()); 
  ) Else if (getTotalPage ()> 0) ( 
  Return getText (). Substring ((getCurrentPage () - 1) * getSizePerPage ()); 
  ) 
  ) Catch (Exception e) ( 
  E.printStackTrace (); 
  ) 
  Return null; 
  ) 

  / ** 
  * @ Return Returns the current page number. 
  * / 
  Public int getCurrentPage () ( 
  If (currentPage <= 0) currentPage = 1; 

  Return currentPage; 
  ) 

  / ** 
  * Set up the current page, from the beginning. 
*
  * @ Param currentPage 
  * The number to set the current page number. 
  * / 
  Public void setCurrentPage (int currentPage) ( 
  If (currentPage <= 0) ( 
  CurrentPage = 1; 
  ) 
  This.currentPage = currentPage; 
  ) 

  / ** 
  * @ Return Returns the total number of pages, if there is no data on a return. 
  * / 
  Public int getTotalPage () ( 
  If (getText () == null) totalPage = 0; 
  TotalPage = (int) Math.ceil (1.0 * getText (). Length () / getSizePerPage ()) / / total number of pages 

  If (totalPage == 0) 
  TotalPage = 1; 
  Return totalPage; 
  ) 

  / ** 
  * @ Param totalPage 
  * The totalPage to set. 
  * / 
  Public void setTotalPage (int totalPage) ( 
  This.totalPage = totalPage; 
  ) 

  Public static void main (String [] args) ( 
  StringPager pager = new StringPager (); 
  Pager.setSizePerPage (5); 
  Pager.setText ( "12345678901"); 
  Pager.setCurrentPage (2); 

  System.out.println (pager.getTotalPage ()); 
  System.out.println (pager.getCurrentPagedText ()); 
  ) 

  / ** 
  * @ Return Returns the number of characters per page. 
  * / 
  Public int getSizePerPage () ( 
  Return sizePerPage; 
  ) 

  / ** 
  * @ Param sizePerPage 
  * The number of characters per page to set. 
  * / 
  Public void setSizePerPage (int sizePerPage) ( 
  This.sizePerPage = sizePerPage; 
  ) 

  / ** 
  * @ Return Returns the paging needs of the long string. 
  * / 
  Public String getText () ( 
  Return text; 
  ) 

  / ** 
  * @ Param text 
  * The need for paging long strings to set. 
  * / 
  Public void setText (String text) ( 
  This.text = text; 
  ) 
  ) 

  Below are the jsp call: testpage.jsp (download) 
  </ Td> <td width="175" valign="top" class="ArticleTeitle"> 
  </ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle"> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , ,

Releated Java Articles

Comments

Leave a Reply