⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 caidan.java

📁 JAVA 写的五子棋
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

class StopHandler implements ActionListener {
	DrawLine a;

	MouseTracker m1[];

	public StopHandler(DrawLine a) {
		this.a = a;
		m1 = ButtonPanel.mt;

	}

	public void actionPerformed(ActionEvent e) {

		

		if (m1[0].i % 2 == 0) {
			Pane1.timer.stop();
		} else {
			Pane2.timer.stop();
		}

	}
}

class Musicon implements ActionListener{
	public void actionPerformed(ActionEvent e){
		Caidan.muvalue=true;
		//System.out.println("xuanzele"+Caidan.jshvalue);
	}
}

class Musicoff implements ActionListener{
	public void actionPerformed(ActionEvent e){
		Caidan.muvalue=false;
		//System.out.println("music is stop");
		//System.out.println(Caidan.muvalue);
	}
}

class GobackHandler implements ActionListener {
	DrawLine a;

	MouseTracker m1[];

	public GobackHandler(DrawLine a) {
		this.a = a;
		m1 = ButtonPanel.mt;
	}

	public void actionPerformed(ActionEvent e) {
		int bianChang = 15;
		int qp2[][] = new int[bianChang][bianChang];
		qp2 = MouseTracker.getqp();
		if (m1[0].i > 0) {
			Qizi[] qizi = m1[0].getQizi();
			qizi = m1[0].getQizi();
			a.remove(qizi[m1[0].i]);

			qp2[qizi[m1[0].i].gethang()][qizi[m1[0].i].getlie()] = 0;
			m1[0].i = m1[0].i - 1;
			a.repaint();
			
		}

		else {
			JOptionPane.showMessageDialog(a, "不能再悔棋了哦!");
		}

	}
}

class ExitHandler implements ActionListener {
	public ActionListener listener;
	public void actionPerformed(ActionEvent e) {
		//MessageDialog messagedialog = new MessageDialog();
		//messagedialog.showmessagetoconfirm();
		 
		int a;
		a=JOptionPane.showConfirmDialog(null,"确定推出游戏?","Confirm to exit",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
		
		if(a==JOptionPane.YES_OPTION){
			
			ChessBoard.getJF().dispose();
			listener=new listenerHandler3();
			Timer time=new Timer(12000,listener);
			time.start();
			exit x=new exit();
			
		}

		else{
			if(a==JOptionPane.NO_OPTION){
				
			}
		}
		
		
		
	}
}
class Qp1listener implements ActionListener{
	public void actionPerformed(ActionEvent e){
		DrawLine.value=true;
		ChessBoard.a.repaint();
	}
}
class Qp2listener implements ActionListener{
	public void actionPerformed(ActionEvent e){
		DrawLine.value=false;
		ChessBoard.a.repaint();
	}
}
class listenerHandler3 implements ActionListener{
	public void actionPerformed(ActionEvent e){
		exit.close();
	}
}

class AuthorHandler implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		MessageDialog messagedialog = new MessageDialog();
		messagedialog.showmessageofauthor();
	}
}

class FiveHandler implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		JFrame a = new JFrame("五子棋规则");
		a.setContentPane(new rule());
		a.pack();
		a.setVisible(true);

	}
}

class rule extends JPanel {
	private JTextArea textarea;

	public rule() {
		String text = "黑白双方依次落子,任一方先在棋盘上形成横向、竖向、斜向的\n"
				+ "连续的相同颜色的五个(含五个以上)棋子的一方为胜。禁手规则鉴于无\n"
				+ "禁手规则黑棋必胜,人们不断采用一些方法限制黑棋先行的优势,以平衡\n"
				+ "黑白双方的形式。于是针对黑棋的各种禁手逐渐形成。禁手最简单地说就\n"
				+ "是一手棋形成长连(连成五个以上连续相同的棋子),或两个以上的活三,\n"
				+ "或者两个以上的四,并且这些四、活三和长连都要包括这一手棋。并且规定,\n"
				+ "当禁与连五同时出现时为黑方取胜禁手不成立禁手是针对黑棋而言的,白棋\n" + "没有任何禁手。";
		;
		textarea = new JTextArea(text, 20, 40);
		textarea.setEditable(false);
		textarea.setBackground(new Color(0, 0, 200));
		textarea.setForeground(Color.white);
		add(new JScrollPane(textarea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));

	}

}

class VersionHandler implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		MessageDialog messagedialog = new MessageDialog();
		messagedialog.showmessageofversion();
	}

}

class XianshouHandler implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		//JFrame j = new JFrame("猜单双");
		CaiXianShou cai = new CaiXianShou();
		//j.getContentPane().add(cai, BorderLayout.CENTER);
		//cai.init();
		//j.pack();
		//j.setSize(100, 100);
		//j.setVisible(true);
	}
}

class ImageChooseHander implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		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();
			// log.append("Attaching file: " + file.getPath()
			// + "." + "\n");

			String path = file.getPath();

			ImageIcon icon1 = new ImageIcon(path);

			if (icon1.getIconHeight() < 750 || icon1.getIconWidth() < 900) {
				JOptionPane.showMessageDialog(null,"请选择至少为(900,750)的图片当背景,谢谢");
			}

			else {
				ChessBoard.getJL().setIcon(icon1);
			}

		} else {

		}
	}
}

class ImageFileView extends FileView {
	ImageIcon jpgIcon = new ImageIcon("images/jpgIcon.gif");

	ImageIcon gifIcon = new ImageIcon("images/gifIcon.gif");

	ImageIcon tiffIcon = new ImageIcon("images/tiffIcon.gif");

	public String getName(File f) {
		return null;
	}

	public String getDescription(File f) {
		return null;
	}

	public Boolean isTraversable(File f) {
		return null;
	}

	public String getTypeDescription(File f) {
		String extension = Utils.getExtension(f);
		String type = null;

		if (extension != null) {
			if (extension.equals(Utils.jpeg) || extension.equals(Utils.jpg)) {
				type = "JPEG Image";
			} else if (extension.equals(Utils.gif)) {
				type = "GIF Image";
			} else if (extension.equals(Utils.tiff)
					|| extension.equals(Utils.tif)) {
				type = "TIFF Image";
			}
		}
		return type;
	}

	public Icon getIcon(File f) {
		String extension = Utils.getExtension(f);
		Icon icon = null;

		if (extension != null) {
			if (extension.equals(Utils.jpeg) || extension.equals(Utils.jpg)) {
				icon = jpgIcon;
			} else if (extension.equals(Utils.gif)) {
				icon = gifIcon;
			} else if (extension.equals(Utils.tiff)
					|| extension.equals(Utils.tif)) {
				icon = tiffIcon;
			}
		}
		return icon;
	}
}

class ImageFilter extends javax.swing.filechooser.FileFilter {

	// 接收所有的路径和所有的gif, jpg, 以及tiff 文件.
	public boolean accept(File f) {
		if (f.isDirectory()) {
			return true;
		}
		String extension = Utils.getExtension(f);
		if (extension != null) {
			if (extension.equals(Utils.tiff) || extension.equals(Utils.tif)
					|| extension.equals(Utils.gif)
					|| extension.equals(Utils.jpeg)
					|| extension.equals(Utils.jpg)) {
				return true;
			} else {
				return false;
			}
		}
		return false;
	}

	// 过滤器的描述
	public String getDescription() {
		return "图形文件";
	}
}

class ImagePreview extends JComponent implements PropertyChangeListener {
	ImageIcon thumbnail = null;

	File file = null;

	public ImagePreview(JFileChooser fc) {
		setPreferredSize(new Dimension(100, 50));
		fc.addPropertyChangeListener(this);
	}

	public void loadImage() {
		if (file == null) {
			return;
		}

		ImageIcon tmpIcon = new ImageIcon(file.getPath());
		if (tmpIcon.getIconWidth() > 90) {
			thumbnail = new ImageIcon(tmpIcon.getImage().getScaledInstance(90,
					-1, Image.SCALE_DEFAULT));
		} else {
			thumbnail = tmpIcon;
		}
	}

	public void propertyChange(PropertyChangeEvent e) {
		String prop = e.getPropertyName();
		if (prop.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
			file = (File) e.getNewValue();
			if (isShowing()) {
				loadImage();
				repaint();
			}
		}
	}

	public void paintComponent(Graphics g) {
		if (thumbnail == null) {
			loadImage();
		}
		if (thumbnail != null) {
			int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
			int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;

			if (y < 0) {
				y = 0;
			}

			if (x < 5) {
				x = 5;
			}
			thumbnail.paintIcon(this, g, x, y);
		}
	}
}

class Utils {
	public final static String jpeg = "jpeg";

	public final static String jpg = "jpg";

	public final static String gif = "gif";

	public final static String tiff = "tiff";

	public final static String tif = "tif";

	// 获取文件后缀名.
	public static String getExtension(File f) {
		String ext = null;
		String s = f.getName();
		int i = s.lastIndexOf('.');
		if (i > 0 && i < s.length() - 1) {
			ext = s.substring(i + 1).toLowerCase();
		}
		return ext;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -