📄 option.java
字号:
import java.awt.*;
import javax.swing.*;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
public class Option extends JFrame implements ActionListener {
private JLabel background = new JLabel("选择背景图:");
private JButton scan = new JButton("浏览");
// private ActionListener scanHandler=new ScanHandler();
private JLabel chessboard = new JLabel("选择棋盘:");
private JRadioButton touming = new JRadioButton("透明", false);
private JRadioButton butouming = new JRadioButton("不透明", true);
private ButtonGroup group1 = new ButtonGroup();
// private ActionListener toumingHandler=new ToumingHandler();
// private ActionListener butoumingHandler=new ButoumingHandler();
private JLabel totaltime = new JLabel("选择总共时间:");
private JRadioButton five = new JRadioButton("10分钟", false);
private JRadioButton ten = new JRadioButton("20分钟", true);
private JRadioButton fifteen = new JRadioButton("30分钟", false);
private ButtonGroup group2 = new ButtonGroup();
// private ActionListener fiveHandler=new FivHandler();
// private ActionListener tenHandler=new TenHandler();
// private ActionListener fifteenHandler=new FifteenHandler();
private static JLabel forbid = new JLabel("选择禁手:");
private JRadioButton yes = new JRadioButton("开", true);
private JRadioButton no = new JRadioButton("关", false);
private ButtonGroup group3 = new ButtonGroup();
// private ActionListener yesHandler=new YesHandler();
// private ActionListener noHandler=new NoHandler();
private JLabel music = new JLabel("音乐开关:");
private JRadioButton yes1 = new JRadioButton("开", true);
private JRadioButton no1 = new JRadioButton("关", false);
private ButtonGroup group4 = new ButtonGroup();
// private ActionListener yes1Handler=new Yes1Handler();
// private ActionListener no1Handler=new No1Handler();
private JButton jb1 = new JButton("确定");
// private ActionListener jb1hander=new Jb1hander();
private JButton jb2 = new JButton("取消");
// private ActionListener jb2hander=new Jb2hander();
public static JFrame f;
public static boolean value=false;
public static String settime="20";
public static ImageIcon icon;
public static boolean imagevalue=false;
public static boolean jinshouvalue=true;
public static boolean musicvalue=true;
public Option() {
//f = new JFrame("五子棋游戏选项......");
super("五子棋游戏选项......");
Container c = getContentPane();
c.setLayout(null);
totaltime.setSize(100, 15);
totaltime.setLocation(40, 30);
five.setSize(180, 15);
five.setLocation(160, 30);
five.addActionListener(this);
ten.setSize(180, 15);
ten.setLocation(160, 50);
ten.addActionListener(this);
fifteen.setSize(180, 15);
fifteen.setLocation(160, 70);
fifteen.addActionListener(this);
group2.add(five);
group2.add(ten);
group2.add(fifteen);
c.add(totaltime);
c.add(five);
c.add(ten);
c.add(fifteen);
forbid.setSize(100, 15);
forbid.setLocation(40, 105);
yes.setSize(180, 15);
yes.setLocation(160, 105);
yes.addActionListener(this);
no.setSize(180, 15);
no.setLocation(160, 125);
no.addActionListener(this);
group3.add(yes);
group3.add(no);
c.add(forbid);
c.add(yes);
c.add(no);
music.setSize(100, 15);
music.setLocation(40, 160);
yes1.setSize(180, 15);
yes1.setLocation(160, 160);
yes1.addActionListener(this);
no1.setSize(180, 15);
no1.setLocation(160, 180);
no1.addActionListener(this);
group4.add(yes1);
group4.add(no1);
c.add(music);
c.add(yes1);
c.add(no1);
chessboard.setSize(100, 15);
chessboard.setLocation(40, 215);
touming.setSize(180, 15);
touming.setLocation(160, 215);
touming.addActionListener(this);
butouming.setSize(180, 15);
butouming.setLocation(160, 235);
butouming.addActionListener(this);
group1.add(touming);
group1.add(butouming);
c.add(chessboard);
c.add(touming);
c.add(butouming);
background.setSize(100, 15);
background.setLocation(40, 280);
scan.setSize(70, 20);
scan.setLocation(160, 280);
scan.addActionListener(this);
c.add(background);
c.add(scan);
jb1.setSize(70, 30);
jb2.setSize(70, 30);
jb1.setLocation(60, 350);
jb2.setLocation(160, 350);
jb1.addActionListener(this);
jb2.addActionListener(this);
c.add(jb1);
c.add(jb2);
setSize(300, 450);
setLocation(200, 150);
setVisible(true);
//System.out.println(value);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == five) {
Caidan.Ctime[0]=10;
settime="10";
}
if (e.getSource() == ten) {
Caidan.Ctime[0]=20;
settime="20";
}
if (e.getSource() == fifteen) {
Caidan.Ctime[0]=30;
settime="30";
}
if (e.getSource() == yes) {
jinshouvalue=true;
}
if (e.getSource() == no) {
jinshouvalue=false;
}
if (e.getSource() == yes1) {
musicvalue=true;
}
if (e.getSource() == no1) {
musicvalue=false;
}
if (e.getSource() == touming) {
value=true;
}
if (e.getSource() == butouming) {
value=false;
}
if (e.getSource() == scan) {
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new ImageFilter());
fc.setFileView(new ImageFileView());
fc.setAccessory(new ImagePreview(fc));
int returnVal = fc.showDialog(ChessBoard.getJF(), "打开");
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
String path = file.getPath();
ImageIcon icon1 = new ImageIcon(path);
if (icon1.getIconHeight() < 750 || icon1.getIconWidth() < 900) {
JOptionPane.showMessageDialog(null,"请选择至少为(900,750)的图片当背景,谢谢");
}
else {
icon=icon1;
}
} else {
}
}
if (e.getSource() == jb1) {
this.dispose();
ChessBoard chessBoard = new ChessBoard();
}
if (e.getSource() == jb2) {
this.dispose();
Caidan.Ctime[0]=20;
settime="20";
value=false;
icon=null;
//imagevalue=true;
ChessBoard chessBoard = new ChessBoard();
}
}
}
/*
* class ScanHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } }
*
* class ToumingHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } } class ButoumingHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } }
*
* class FivHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } } class TenHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } } class FifteenHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } }
*
* class YesHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } } class NoHandler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } } class Yes1Handler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* } } class No1Handler implements ActionListener{ public void
* actionPerformed(ActionEvent e){
* }
* } class Jb1hander implements ActionListener{ public void
* actionPerformed(ActionEvent e){ Option.f.dispose(); } }
*
* class Jb2hander implements ActionListener{ public void
* actionPerformed(ActionEvent e){ Option.f.dispose(); } }
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -