基于Java SWing的游戏界面设计
战机选择
private void backwardActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//图片地址数组下标切换
index++;
if (index > 3) {
index = 0;
}
//图片切换
new Thread(new Runnable() {
@Override
public void run() {
fighterPlane.setIcon(new ImageIcon(planesPath[index]));
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}).start();
}
private void forwardActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//图片地址数组下标切换
index--;
if (index < 0) {
index = 3;
}
//图片切换
new Thread(new Runnable() {
@Override
public void run() {
fighterPlane.setIcon(new ImageIcon(planesPath[index]));
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}).start();
}
游戏界面背景