[該代碼無法100%正確工作。 當我點擊下一步它會改變圖片(它工作)。但是當我按previouse按鈕去previouse圖片它不會顯示previouse圖片。它會顯示下一張圖片,然後當前圖片再顯示prevoiuse圖片。 幫我請 ] [1]java:按next和previouse按鈕更改圖片
//next picture
int count=0;
String[] imagenames={"black.png","blue.png","gray.png","green.png","orange.png","purple.png","red.png","yellow.png"};
private void btnnextActionPerformed(java.awt.event.ActionEvent evt) {
ImageIcon[] imagelist= new ImageIcon[8];
for(int i = 0; i < imagelist.length;i++){
imagelist[i]= new ImageIcon(getClass().getResource("/images/"+ imagenames[i]));
if(count<0) count = 0;
if(count>=0 && count < imagenames.length){
jLabel1.setIcon(imagelist[count]);
count++;
}
}
}
//previous picture
//i use the same array imagenames
private void btnbackActionPerformed(java.awt.event.ActionEvent evt) {
ImageIcon[] imagelist= new ImageIcon[8];
for(int i = 0; i < imagelist.length;i++){
imagelist[i]= new ImageIcon(getClass().getResource("/images/"+ imagenames[i]));
}
if(count >= imagenames.length)count= imagenames.length-2;
if(count>=0&& count < imagenames.length){
jLabel1.setIcon(imagelist[count]);
count--;
}
}