之三:程序主界面
等级选择“初级”,进入“程序主界面”,效果见下图:
准备工作:
Images文件夹下,放置level.png图片一张。
代码实现:
PCBoard .java
package com.fivechess.view;
public class PCBoard extends Board {
private PCChessBoard2 pcchessboard2;//棋盘
public PCBoard() {
init();
}
public void init() {
pcchessboard2=new PCChessBoard2();
pcchessboard2.setBounds(200, 50, 600, 700);
pcchessboard2.setVisible(true);
add(pcchessboard2);
}
}
//Board类的代码:
package com.fivechess.view;
import java.awt.Graphics;
import javax.swing.JFrame;
public class Board extends JFrame {
public Board() {
setLayout(null); //取消原来布局
setBounds(300,50,800,700);
//init1();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setTitle("雷雷的五子棋");
}
/**
* 绘图
* @param g
*/
public void paint(Graphics g)
{
super.paint(g);
repaint();
}
}
===========================================================================
//棋盘PCChessBoard2类
package com.fivechess.view;
import java.awt.event.MouseEvent;
import javax.swing.JOptionPane;
public class PCChessBoard2 extends ChessBoard2{
public int whichColor=0;
private int ex;
private int ey;
public static int isClose=0;
//落下棋子
@Override
public void mouseMoved(MouseEvent e) {
repaint();
}
@Override
public void mouseClicked(MouseEvent e) {
if(isClose==1) {
return;
}
ex=e.getX();
ey=e.getY();
float x = (ex - 25) / 25;
float y = (ey - 25) / 25;
int x1 = (int) x;
int y1 = (int) y;
}
}
ChessBoard2类
package com.fivechess.view;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JPanel;
/*
* 汇制棋盘的代码
* */
public class ChessBoard2 extends JPanel implements MouseMotionListener,MouseListener{
public Image chessBoardImage;
public Image blackChess;
public Image whiteChess;
public Image buttonBoard;
public static final int COLS=19;
public static final int RAWS=19;//棋盘的行数和列数
public int position[][]=new int[COLS][RAWS];
public ChessBoard2() {
chessBoardImage = Toolkit.getDefaultToolkit().getImage("images/chessBoard.jpg");
blackChess= Toolkit.getDefaultToolkit().getImage("images/black.png");
whiteChess= Toolkit.getDefaultToolkit().getImage("images/white.png");
buttonBoard= Toolkit.getDefaultToolkit().getImage("images/buttonBoard.png");
addMouseListener(this);
}
/**
* 初始化数组为BLANK
*/
public void initStart()
{
for(int i=0;i
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net