Self-encapsulated pagination bar in Java JSE

Source: Internet
Author: User

Many programs cannot be yours if they are not organized! If you find that you have to repeat the same program multiple times, encapsulate it.

This blog is composed of two parts: + source program

/*** @ Title: subpagebar. Java * @ package com. Graduation. myswing * @ Description: Todo (the custom page Toolbar contains the following information: I ~ J (N in total). x entries are displayed on each page. Previous Page y/z page next page) * @ author empty hunting * @ date 08:35:43 * @ version V1.0 */package COM. graduation. myswing; import Java. AWT. flowlayout; import Java. AWT. event. actionevent; import Java. AWT. event. actionlistener; import Java. AWT. event. itemevent; import Java. AWT. event. itemlistener; import javax. swing. jbutton; import javax. swing. jcombobox; import javax. swing. jlabel; import javax. swing. jpanel; public abstract class Extends extends jpanel implements itemlistener, actionlistener {private int allcount, fromrec, endrec, pagesize, pageindex, pagecount; private jlabel labels, tags, pageindexlab; private extends eachcom; private jbutton prebtn, nextbtn; public subpagebar (INT recnums) {This. allcount = recnums; initui (); updatedata ();} private void initui () {// comboboxeachcom = new jcombobox (New String [] {" 20 "," 50 "," 100 "}); // labelcurcountlab = new jlabel (); allcountlab = new jlabel (); pageindexlab = new jlabel (); // buttonprebtn = new jbutton ("Previous Page"); nextbtn = new jbutton ("next page"); // listenereachcom. additemlistener (this); prebtn. addactionlistener (this); nextbtn. addactionlistener (this); this. setlayout (New flowlayout (flowlayout. left); this. add (curcountlab); this. add (allcountlab); this. add (New jlabel ("per page"); th Is. add (eachcom); this. add (New jlabel ("bar"); this. add (prebtn); this. add (pageindexlab); this. add (nextbtn);}/*** @ Description: (update the value of the page bar) */private void updatedata () {// required parameter values: allcount pageindex pagesizepagesize = integer. valueof (eachcom. getselecteditem (). tostring (); fromrec = pageindex * pagesize + 1; if (0 = allcount) {fromrec = 0;} endrec = (pageindex + 1) * pagesize; if (endrec> allcount) {endrec = allcoun T;} pagesize = (0 = pagesize )? 1: pagesize; pagecount = allcount/pagesize-(0 = allcount % pagesize & 0! = Allcount )? 1:0); curcountlab. settext ("th" + fromrec + "~ "+ Endrec +" entries "); allcountlab. settext ("(total" + allcount + ). "); pageindexlab. settext ("no." + (pageindex + 1) + "/" + (pagecount + 1) + "page"); prebtn. setenabled (pageindex> 0); nextbtn. setenabled (pageindex <pagecount);}/*** @ Description: when loading new data, You Need To overload */Public void fresh (INT recnums) {This. allcount = recnums; updatedata () ;}@ overridepublic void itemstatechanged (itemevent e) {// this judgment is required because itemevent is triggered when "selected" or "deselected. if (E. getstatechange () = itemevent. selected) {pageindex = 0; pagesize = integer. valueof (eachcom. getselecteditem (). tostring (); updatedata () ;}@ overridepublic void actionreceivmed (actionevent e) {If (E. getsource () = prebtn) {pageindex --; onclickprebutton (pageindex);} else if (E. getsource () = nextbtn) {pageindex ++; onclicknextbutton (pageindex);} updatedata ();} public abstract void onpagesizechange (INT newpagesize ); public abstract void onclickprebutton (INT pageindex); public abstract void onclicknextbutton (INT pageindex );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.