📄 initial.java
字号:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import javax.swing.*;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class initial extends JFrame {
JButton b1 = new JButton("开始游戏");
JButton b2 = new JButton("载入");
JButton b3 = new JButton("选项");
JButton b4 = new JButton("退出");
Icon bug1 = new ImageIcon("back1.jpg");
JLabel background = new JLabel("", bug1, 0);
Icon bug2 = new ImageIcon("wuziqi1.gif");
// JLabel background1 = new JLabel("", bug2, 0);
JLabel background1;
Icon bug3 = new ImageIcon("wuziqi2.gif");
// JLabel background2 = new JLabel("", bug3, 0);
int n = 0;
public ActionListener listener;
FileInputStream fileau;
AudioStream as;
//FileInputStream fileau=new FileInputStream("start.wav" );
// AudioStream as=new AudioStream(fileau);
public initial() {
super("欢迎进入游戏");
try {
fileau=new FileInputStream("start.wav" );
as=new AudioStream(fileau);
AudioPlayer.player.start(as);
}
catch (Exception e) {}
b1.setBounds(250, 120, 100, 40);
b1.setBackground(new Color(0, 0, 0));
b1.setForeground(Color.white);
add(b1);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
start();
}
});
b2.setBounds(250, 170, 100, 40);
b2.setBackground(new Color(0, 0, 0));
b2.setForeground(Color.white);
add(b2);
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
load();
}
});
b3.setBounds(250, 220, 100, 40);
b3.setBackground(new Color(0, 0, 0));
b3.setForeground(Color.white);
add(b3);
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
option();
}
});
b4.setBounds(250, 270, 100, 40);
b4.setBackground(new Color(0, 0, 20));
b4.setForeground(Color.white);
add(b4);
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
exit();
}
});
background1 = new JLabel();
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (n % 2 == 1) {
background1.setIcon(bug2);
} else
background1.setIcon(bug3);
n++;
}
};
Timer timer;
timer = new Timer(100, listener);
timer.start();
background1.setLocation(110, 20);
background1.setSize(400, 110);
add(background1);
// background2.setLocation(110,20);
// background2.setSize(400,110);
// add(background2);
background.setBounds(0, 0, 600, 400);
add(background);
listener = new listenerHandler();
setSize(600, 400);
setLocation(200, 150);
setVisible(true);
setLayout(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
}
public void start() {
AudioPlayer.player.stop(as);
this.dispose();
ChessBoard chessBoard = new ChessBoard();
}
public void load() {
AudioPlayer.player.stop(as);
this.dispose();
}
public void option() {
AudioPlayer.player.stop(as);
Option opt = new Option();
this.dispose();
}
public void exit() {
showmessagetoconfirm();
}
// public static void main(String[] args){
// initial a = new initial();
// a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// }
public void showmessagetoconfirm() {
int a;
a = JOptionPane.showConfirmDialog(null, "确定推出游戏?", "Confirm to exit",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (a == JOptionPane.YES_OPTION) {
AudioPlayer.player.stop(as);
this.dispose();
listener=new listenerHandler();
Timer time = new Timer(12000, listener);
time.start();
exit x = new exit();
}
else {
if (a == JOptionPane.NO_OPTION) {
}
}
}
}
class listenerHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
exit.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -