首先打開的就是開始界面,點選開始,進入遊戲(老套路了)
package Main;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import music.loginMusic;
/**
*
* @author Administrator
*點選開始進入遊戲界面
*/
public class Main extends JFrame{
JButton jb;
MyPanel mp;
public static void main(String[] args) {
new Main();
}
Main(){
jb = new JButton("确定");
mp = new MyPanel();
//啟動螺旋槳音樂線程
new Thread(new loginMusic()).start();
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//進入關卡選擇界面,将本界面畫闆和按鈕隐藏,進入新面闆
mp.setVisible(false);
jb.setVisible(false);
new Select(Main.this); //把面闆傳過去
}
});
this.setLayout(null);
this.add(jb);
this.add(mp);
jb.setBounds(200, 470, 100, 80);
mp.setBounds(0, 0, 500, 600);
//界面設定
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(500, 600);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}
//登入面闆
class MyPanel extends JPanel{
public void paint(Graphics g){
super.paint(g);
g.drawImage(new ImageIcon("img/login-1.jpg").getImage(),0,0, 500,600, null);
}
}

比較醜的界面,做好在美化把,先把主要功能實作,在這個類中,開啟聲音樂線程,播放螺旋槳的聲音
螺旋槳聲音線程類
package music;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import javazoom.jl.player.Player;
public class loginMusic implements Runnable{
Player player;
@Override
public void run() {
try {
Thread.sleep(10);
BufferedInputStream buffer = new BufferedInputStream(new FileInputStream("mp3/lxj.mp3"));
player = new Player(buffer);
player.play();
} catch (Exception e) {
e.printStackTrace();
}
}
}
點選确定按鈕進入,選擇關卡界面,如圖