[英]Use for-loop index inside variable
我有以下for循環:
for (int i=0; i<5; i++){
if (someVariable==anotherVariable)
jPanel(i).remove(anElement);
}
我想使用for循環遍歷我擁有的JPanels,並從它們中刪除某些元素,我的jPanels分別命名為jPanel0,jPanel1,jPanel2 .... jPanel5
我知道上面的代碼不起作用,我也不知道該怎么做。 任何幫助,將不勝感激
相反,創建一個名為多個變量的jPanel0
, jPanel1
...你應該創建數組JPanel[] panels;
。 然后,您可以在循環中訪問帶有panels[i]
的特定面板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.