package lyj.chess.main;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ChessView extends JFrame {

	private static final long serialVersionUID = -1063545087348605552L;

	static final int ROW_SIZE = 15;

	static final int COLUMN_SIZE = 15;

	static final int WIDTH_SIZE = 500;

	static final int HEIGHT_SIZE = 800;

	static final int CHESS_TYPE = 30;

	public int[][] chess = new int[ROW_SIZE][COLUMN_SIZE];
	
	private JButton start=new JButton();
	private JButton end=new JButton();
	private JLabel msg=new JLabel();

	
	private class ChessPanel extends JPanel implements ActionListener {
		private static final long serialVersionUID = -6047395267529903117L;
		MyAdpater myAdpater=null;

		public ChessPanel() {
			setSize(new Dimension(WIDTH_SIZE, HEIGHT_SIZE));
			start.setText("羲宎蚔牁");
			end.setText("笭陔蚔牁");
			end.setBounds(500, 300, 100, 50);
			start.setBounds(500, 100, 100, 50);
			msg.setBounds(530, 170, 100, 20);
		
			setLayout(null);
			getContentPane().add(start);
			getContentPane().add(msg);
			getContentPane().add(end);
			msg.setBackground(Color.blue);
			end.addActionListener(this);
			start.addActionListener(this);
			myAdpater=new MyAdpater(this,chess,msg);
			addMouseListener(myAdpater);
		

		
		}

		@Override
		protected void paintComponent(Graphics g) {
			for (int i = 0; i < ROW_SIZE; i++) {
				for (int j = 0; j < COLUMN_SIZE; j++) {
					if (i < ROW_SIZE - 1 && j < COLUMN_SIZE - 1) {
						g.setColor(Color.BLACK);
						g.drawRect(i * CHESS_TYPE + 50, j * CHESS_TYPE + 50,CHESS_TYPE, CHESS_TYPE);
					}
					if (chess[j][i] == ChessHelper.BLACK_CHESS) {
						g.setColor(Color.BLACK);
						g.fillOval(i * CHESS_TYPE + 35, j * CHESS_TYPE + 35,
								CHESS_TYPE, CHESS_TYPE);

					} else if (chess[j][i] == ChessHelper.WHITE_CHESS) {
						g.setColor(Color.WHITE);
						g.fillOval(i * CHESS_TYPE + 35, j * CHESS_TYPE + 35,
								CHESS_TYPE, CHESS_TYPE);

					}
				}
			}
		}

		public void actionPerformed(ActionEvent e) {
		if(e.getSource()==end){
			chess=new int[ROW_SIZE][COLUMN_SIZE];
			getMsgLable().setText("");
			myAdpater=new MyAdpater(this,chess,msg);
			myAdpater.setGameStatus(true);
			addMouseListener(myAdpater);
			super.repaint();
		}
			
		}

	}

	public ChessView() {
	
		setBackground(Color.CYAN);
		setSize(800, 700);
		add(new ChessPanel(), java.awt.BorderLayout.CENTER);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public JLabel getMsgLable(){
		return msg;
	}

	public static void main(String[] args) {
		new ChessView();

	}

}
最近下载更多
gzryue  LV6 2023年4月23日
刘鹏yyds  LV10 2022年12月20日
123aa21a  LV5 2021年6月23日
 LV10 2021年6月12日
小小鹿lu  LV1 2021年5月19日
ds0420  LV4 2021年1月4日
Care269031877  LV4 2020年12月18日
lxp66666  LV1 2020年12月6日
3159792465  LV10 2020年10月14日
dengge123  LV13 2020年9月2日
最近浏览更多
20201202038 3月27日
暂无贡献等级
周俊杰  LV1 2023年12月25日
46562026 2023年12月22日
暂无贡献等级
2386136609  LV1 2023年12月17日
qq1434100519  LV1 2023年11月1日
wangjialiang1  LV17 2023年8月20日
2385649653  LV7 2023年6月26日
陈小灏  LV14 2023年6月5日
gzryue  LV6 2023年4月23日
wind12 2023年3月26日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友