Re: [問題] 請問JButton要如何一次寫出數個

看板java作者 (不再嘴砲了)時間18年前 (2008/01/04 22:05), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《Sanbeishuu (三杯鼠)》之銘言: : 目的是要 製作出 26個button : 名稱分別是 ABCDE....Z : 顯示出 ABCDE.....Z : JButton[] asd = {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}; : for(int i=0;i<25;i++) : { : asd[i] = new JButton(""+asd[i]); : add(asd[i]); : asd[i].addActionListener(this); : asd[i].setBounds(i%5*50,(i/6+1)*50,50,50); : JButton[] asd= new JButton[25]; String[] zxc= {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}; for(int i=0;i<zxc.length;i++) { asd[i] = new JButton(""+zxc[i]); add(asd[i]); asd[i].addActionListener(this); asd[i].setBounds(i%5*50,(i/6+1)*50,50,50); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.59.146.254 ※ 編輯: slalala 來自: 61.59.146.254 (01/04 22:05)
文章代碼(AID): #17VZqqwr (java)
文章代碼(AID): #17VZqqwr (java)