首先打开的就是开始界面,点击开始,进入游戏(老套路了)
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();
}
}
}
点击确定按钮进入,选择关卡界面,如图