The code is as follows
Importjava.awt.*;Importjavax.swing.*;//Graphics counter jcounter three-bitclassJcounterextendsJPanel {Private Static Final LongSerialversionuid = 1L; PrivateImageIcon [] Numset = {NewImageIcon ("Image/c0.gif"),NewImageIcon ("Image/c1.gif"), NewImageIcon ("Image/c2.gif"),NewImageIcon ("Image/c3.gif"), NewImageIcon ("Image/c4.gif"),NewImageIcon ("Image/c5.gif"), NewImageIcon ("Image/c6.gif"),NewImageIcon ("Image/c7.gif"), NewImageIcon ("Image/c8.gif"),NewImageIcon ("Image/c9.gif"), }; PrivateJButton [] counter = {NewJButton (Numset[0]),NewJButton (Numset[0]),NewJButton (numset[0])}; Private intCounternum; PrivateInsets space; PublicJcounter () { This(0); } PublicJcounter (intnum) { Super(); SetSize (23, 39); Space=NewInsets (0,0,0,0); This. Counternum =num; for(inti=0; i< 3; i++) {counter[i].setsize (13,23); Counter[i].setmargin (space); Add (Counter[i]); } This. setvisible (true); Resetimage (); } Public intGetcounternum () {return(Counternum); } Private voidSetcounternum (intnum) { This. Counternum =num; } Private voidResetimage () {intones, tens, hundreds; Ones= counternum% 10 ; Tens= counternum% 100/10; Hundreds= (counternum)% 1000/100; This. counter[0].seticon (numset[hundreds]); This. counter[1].seticon (Numset[tens]); This. counter[2].seticon (Numset[ones]); } Public voidResetcounter (intnum) {setcounternum (num); Resetimage (); This. repaint (); } Public Static voidMain (string[] args) {JFrame JF=NewJFrame ("Test"); Jf.setsize (23,39); Jcounter JC=NewJcounter (); Jf.setcontentpane (JC); Jf.show (); Jc.resetcounter (394); } }
<ignore_js_op>
Detailed Description: http://java.662p.com/thread-3209-1-1.html
Java Minesweeper Game source case Project