# ChessFrame **Repository Path**: chinese-chess/chess-frame ## Basic Information - **Project Name**: ChessFrame - **Description**: Chess can make our happy and interesting - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-22 - **Last Updated**: 2021-06-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ChessFrame #基本代码设计`这里输入代码`package com.chess; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; public class ChessMainframe extends JFrame implements ActionListener, MouseListener,Runnable { ChessManBehavior play[] = new ChessManBehavior[32]; JLabel image; Container con; JToolBar jmain; JButton anew, repent, exit; JLabel text; public ChessMainframe(String title) { con = this.getContentPane(); con.setLayout(null); this.setTitle(title); jmain = new JToolBar(); text = new JLabel("欢迎来到象棋荣耀"); text.setToolTipText("信息提示"); anew = new JButton("新游戏"); anew.setToolTipText("重新开始新的一局"); exit = new JButton("退出"); exit.setToolTipText("退出象棋对弈系统"); repent = new JButton("悔棋"); repent.setToolTipText("返回上次走棋的位置"); jmain.setLayout(new GridLayout(0, 4)); jmain.add(anew); jmain.add(repent); jmain.add(exit); jmain.add(text); jmain.setBounds(0, 0, 558, 30); con.add(jmain); draeChessMain(); for(int i=0;i<32;i++) { con.add(play[i]); play[i].addMouseListener(this); } con.add(image=new JLabel(new ImageIcon("image/main.gif"))); image.setBounds(0,30,558,620); image.addMouseListener(this); Dimension screeSize=Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation(screeSize.width/2-228,screeSize.height/2-350); this.setIconImage(new ImageIcon("image/红将.gif").getImage()); this.setResizable(false); this.setSize(558,676); this.setVisible(true); } public void draeChessMain() { int i, k; Icon in = null; in = new ImageIcon("image/黑车.gif"); for (i = 0, k = 24; i < 2; i++, k += 456) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 56, 55, 55); play[i].setName("车1"); } in = new ImageIcon("image/黑马.gif"); for (i = 4, k = 81; i < 6; i++, k += 342) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 56, 55, 55); play[i].setName("马1"); } in = new ImageIcon("image/黑象.gif"); for (i = 8, k = 138; i < 10; i++, k += 228) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 56, 55, 55); play[i].setName("象1"); } in = new ImageIcon("image/黑士.gif"); for (i = 12, k = 195; i < 14; i++, k += 114) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 56, 55, 55); play[i].setName("士1"); } in = new ImageIcon("image/黑卒.gif"); for (i = 16, k = 24; i < 21; i++, k += 114) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 227, 55, 55); play[i].setName("卒1" + i); } in = new ImageIcon("image/黑炮.gif"); for (i = 26, k = 81; i < 28; i++, k += 342) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 170, 55, 55); play[i].setName("炮1" + i); } in = new ImageIcon("image/黑将.gif"); play[30] = new ChessManBehavior(in); play[30].setBounds(252, 56, 55, 55); play[30].setName("将1"); in = new ImageIcon("image/红车.gif"); for (i = 2, k = 24; i < 4; i++, k += 456) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 569, 55, 55); play[i].setName("车2"); } in = new ImageIcon("image/红马.gif"); for (i = 6, k = 81; i < 8; i++, k += 342) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 569, 55, 55); play[i].setName("红马2"); } in = new ImageIcon("image/红象.gif"); for (i = 10, k = 138; i < 12; i++, k += 228) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 569, 55, 55); play[i].setName("红象2"); } in = new ImageIcon("image/红士.gif"); for (i = 14, k = 195; i < 16; i++, k += 114) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 569, 55, 55); play[i].setName("红士2"); } in = new ImageIcon("image/红卒.gif"); for (i = 21, k = 24; i < 26; i++, k += 114) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 398, 55, 55); play[i].setName("红卒" + i); } in = new ImageIcon("image/红炮.gif"); for (i = 28, k = 81; i < 30; i++, k += 342) { play[i] = new ChessManBehavior(in); play[i].setBounds(k, 455, 55, 55); play[i].setName("炮2" + i); } in=new ImageIcon("image/红将.gif"); play[31] = new ChessManBehavior(in); play[31].setBounds(252, 569, 55, 55); play[31].setName("帅"); } @Override public void actionPerformed(ActionEvent e) { } @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void run() { } } 基本实现的图![输入图片说明](https://images.gitee.com/uploads/images/2021/0622/195821_4af75819_9319542.jpeg "屏幕截图 2021-06-22 195700.jpg")