| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1184 人关注过本帖
标题:象棋一chessApp.java-->千里冰封转移
只看楼主 加入收藏
编写蓝图
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2005-11-28
收藏
 问题点数:0 回复次数:5 
象棋一chessApp.java-->千里冰封转移

package chess;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;

public class chessFrame extends JFrame implements MouseListener,
MouseMotionListener {
JPanel contentPane;
//32个棋子
JLabel play[]=new JLabel[6];
JMenuBar jMenuBar1 = new JMenuBar();
JMenu file = new JMenu();
JMenu game = new JMenu();
JMenu help = new JMenu();
JMenuItem open = new JMenuItem();
JMenuItem repent = new JMenuItem();
JMenuItem save = new JMenuItem();
JMenuItem createHost = new JMenuItem();
JMenuItem createClient = new JMenuItem();
JMenuItem breakConnect = new JMenuItem();
JMenuItem exit = new JMenuItem();
JMenuItem jMenuItem8 = new JMenuItem();
JMenuItem defaultset = new JMenuItem();
JMenuItem gamexplain = new JMenuItem();
JMenuItem aboutgame = new JMenuItem();
JLabel jLabel1 = new JLabel();
ImageIcon iicc = new ImageIcon("img/CChess.gif");
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
JButton btnstart = new JButton();
JButton btnrepent = new JButton();
JButton btnpeace = new JButton();
JButton btngiveup = new JButton();
JButton btnsave = new JButton();
JButton btnend = new JButton();
JLabel jLabel2 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jlbwin = new JLabel();
JLabel jlbpeace = new JLabel();
JLabel jlblost = new JLabel();
JLabel jLabel3 = new JLabel();
JList jList1 = new JList();
JTextArea jTextArea1 = new JTextArea();
JButton btnsend = new JButton();
ImageIcon iiwin = new ImageIcon("img/winflag.gif");
ImageIcon iipeace = new ImageIcon("img/peaceflag.jpg");
ImageIcon iilost = new ImageIcon("img/loseflag.gif");
TitledBorder titledBorder1 = new TitledBorder("");
public chessFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
drawChessMan();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {

contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
this.setJMenuBar(jMenuBar1);
setSize(new Dimension(526, 626));
setTitle("中国象棋--网络对战");
file.setActionCommand("file");
file.setText("文件");
game.setActionCommand("game");
game.setText("游戏");
help.setActionCommand("help");
help.setText("帮助");
open.setActionCommand("open");
open.setText("打开");
repent.setActionCommand("repent");
repent.setText("悔棋");
save.setActionCommand("save");
save.setText("保存");
createHost.setActionCommand("createHost");
createHost.setText("新建主机");
createClient.setActionCommand("createClient");
createClient.setText("连接主机");
breakConnect.setAction(null);
breakConnect.setActionCommand("breakConnect");
breakConnect.setText("断开连接");
exit.setActionCommand("exit");
exit.setText("退出");
jMenuItem8.setText("人机对战");
defaultset.setActionCommand("defaultset");
defaultset.setText("默认设置");
gamexplain.setActionCommand("gamexplain");
gamexplain.setText("游戏说明");
aboutgame.setActionCommand("aboutgame");
aboutgame.setText("关于游戏");
jLabel1.setBorder(BorderFactory.createEtchedBorder());
jLabel1.setIcon(iicc);
jLabel1.setBounds(new Rectangle(0,0, 446, 497));
iicc.setImageObserver(jLabel1);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setToolTipText("");
jPanel1.setBounds(new Rectangle(445, 11, 81, 153));
jPanel1.setLayout(null);
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setToolTipText("用时");
jPanel2.setBounds(new Rectangle(446, 174, 81, 137));
jPanel2.setLayout(null);
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setToolTipText("");
jPanel3.setBounds(new Rectangle(445, 320, 81, 177));
jPanel3.setLayout(null);
btnstart.setBounds(new Rectangle( -1, 0, 83, 25));
btnstart.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
btnstart.setActionCommand("btnstart");
btnstart.setText("开 局");
btnrepent.setBounds(new Rectangle( -1, 24, 83, 25));
btnrepent.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
btnrepent.setActionCommand("btnrepent");
btnrepent.setText("悔 棋");
btnpeace.setBounds(new Rectangle( -3, 48, 83, 25));
btnpeace.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
btnpeace.setActionCommand("btnpeace");
btnpeace.setText("求 和");
btngiveup.setBounds(new Rectangle( -1, 72, 83, 25));
btngiveup.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
btngiveup.setActionCommand("btngiveup");
btngiveup.setText("弃 权");
btnsave.setBounds(new Rectangle(0, 96, 83, 25));
btnsave.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
btnsave.setActionCommand("btnsave");
btnsave.setText("保 存");
btnend.setBounds(new Rectangle(0, 121, 83, 27));
btnend.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
btnend.setActionCommand("btnend");
btnend.setText("结 束");
jLabel2.setFont(new java.awt.Font("华文行楷", Font.BOLD, 26));
jLabel2.setText("本 方");
jLabel2.setBounds(new Rectangle(0, 0, 81, 34));
jLabel4.setFont(new java.awt.Font("华文行楷", Font.BOLD, 26));
jLabel4.setText("对 方");
jLabel4.setBounds(new Rectangle(1, 71, 79, 35));
jLabel5.setFont(new java.awt.Font("华文行楷", Font.BOLD, 15));
jLabel5.setText("00:00:00");
jLabel5.setBounds(new Rectangle(4, 110, 75, 23));
jLabel6.setFont(new java.awt.Font("华文行楷", Font.BOLD, 15));
jLabel6.setText("00:00:00");
jLabel6.setBounds(new Rectangle(4, 37, 72, 27));
jlbwin.setFont(new java.awt.Font("华文行楷", Font.BOLD, 15));
jlbwin.setIcon(iiwin);
jlbwin.setText(" 胜0局");
jlbwin.setBounds(new Rectangle(0, 0, 81, 65));
jlbpeace.setFont(new java.awt.Font("华文行楷", Font.BOLD, 15));
jlbpeace.setIcon(iipeace);
jlbpeace.setText(" 平0局");
jlbpeace.setBounds(new Rectangle(4, 72, 73, 56));
jlblost.setFont(new java.awt.Font("华文行楷", Font.BOLD, 15));
jlblost.setIcon(iilost);
jlblost.setText(" 负0局");
jlblost.setBounds(new Rectangle(4, 134, 74, 64));
jLabel3.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
jLabel3.setBorder(BorderFactory.createEtchedBorder());
jLabel3.setText("留 言");
jLabel3.setBounds(new Rectangle(0, 585, 73, 41));
jList1.setBorder(BorderFactory.createEtchedBorder());
jList1.setBounds(new Rectangle(0, 496, 526, 90));
jTextArea1.setBorder(titledBorder1);
jTextArea1.setText("jTextArea1");
jTextArea1.setBounds(new Rectangle(72, 585, 374, 43));
btnsend.setBounds(new Rectangle(445, 585, 81, 41));
btnsend.setFont(new java.awt.Font("华文行楷", Font.BOLD, 19));
btnsend.setActionCommand("btnsend");
btnsend.setText("发 送");
iiwin.setDescription("img/winflag.gif");
iiwin.setImageObserver(null);
iipeace.setImageObserver(jlbpeace);
iilost.setImageObserver(jlblost);
contentPane.setOpaque(true);
jMenuBar1.add(file);
jMenuBar1.add(game);
jMenuBar1.add(help);
file.add(open);
file.add(repent);
file.add(save);
file.addSeparator();
file.add(createHost);
file.add(createClient);
file.add(breakConnect);
file.addSeparator();
file.add(exit);
game.add(jMenuItem8);
game.add(defaultset);
help.add(gamexplain);
help.add(aboutgame);
contentPane.add(jLabel1, null);
jPanel1.add(btnstart);
jPanel1.add(btnrepent);
jPanel1.add(btnpeace);
jPanel1.add(btngiveup);
jPanel1.add(btnsave);
jPanel1.add(btnend);
jPanel2.add(jLabel2);
jPanel2.add(jLabel4);
jPanel2.add(jLabel6);
jPanel2.add(jLabel5);
contentPane.add(jPanel1);
contentPane.add(jPanel3);
contentPane.add(jList1);
contentPane.add(jLabel3);
contentPane.add(jTextArea1);
contentPane.add(btnsend);
contentPane.add(jPanel2);
jPanel3.add(jlbwin);
jPanel3.add(jlbpeace);
jPanel3.add(jlblost);
}
public void drawChessMan(){
int i,k;
Icon in;
//车
in=new ImageIcon("img/0ju.jpg");
for(i=0,k=10;i<2;i++,k+=385){
play[i].setBounds(k,10,40,40);
play[i].setName("jlbju0");
}
//马
in=new ImageIcon("img/0ma.jpg");
for (i=2,k=60;i<4;i++,k+=285)
{
play[i].setBounds(k,10,40,40);
play[i].setName("jlbma0");
}

//相
in=new ImageIcon("img/0xiang.jpg");
for (i=4,k=105;i<10;i++,k+=195)
{
play[i].setBounds(k,10,40,40);
play[i].setName("jlbxiang0");
}
//注册棋子移动监听
for (int j=0;j<6;j++)
{
contentPane.add(play[i]);
play[i].addMouseListener(this);
}


}

/**
* Invoked when the mouse button has been clicked (pressed and released)
* on a component.
*
* @param e MouseEvent
* @todo Implement this java.awt.event.MouseListener method
*/
public void mouseClicked(MouseEvent e) {
}

/**
* Invoked when a mouse button has been pressed on a component.
*
* @param e MouseEvent
* @todo Implement this java.awt.event.MouseListener method
*/
public void mousePressed(MouseEvent e) {
}

/**
* Invoked when a mouse button has been released on a component.
*
* @param e MouseEvent
* @todo Implement this java.awt.event.MouseListener method
*/
public void mouseReleased(MouseEvent e) {
}

/**
* Invoked when the mouse enters a component.
*
* @param e MouseEvent
* @todo Implement this java.awt.event.MouseListener method
*/
public void mouseEntered(MouseEvent e) {
}

/**
* Invoked when the mouse exits a component.
*
* @param e MouseEvent
* @todo Implement this java.awt.event.MouseListener method
*/
public void mouseExited(MouseEvent e) {
}

/**
* Invoked when a mouse button is pressed on a component and then dragged.
*
* @param e MouseEvent
* @todo Implement this java.awt.event.MouseMotionListener method
*/
public void mouseDragged(MouseEvent e) {
}

/**
* Invoked when the mouse cursor has been moved onto a component but no
* buttons have been pushed.
*
* @param e MouseEvent
* @todo Implement this java.awt.event.MouseMotionListener method
*/
public void mouseMoved(MouseEvent e) {
}
}

搜索更多相关主题的帖子: 象棋 java chessApp 千里冰封 JMenu 
2006-04-11 12:25
del000
Rank: 1
等 级:新手上路
威 望:1
帖 子:79
专家分:0
注 册:2006-9-8
收藏
得分:0 
好东西~~~
2006-09-20 10:34
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
发错地方啊,这种帖子应该发到J2SE版去

可惜不是你,陪我到最后
2006-09-20 12:09
jch39
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-9-11
收藏
得分:0 
为什么我编译通过后,在运行的时候出来这个
[IMG]G:\Documents and Settings\jch\My Documents\11.jpg[/IMG]
2006-09-20 12:59
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
出来什么,看不到

可惜不是你,陪我到最后
2006-09-20 13:10
xwb926
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-2-22
收藏
得分:0 
编译可以通过,不过抛出EXCEPTION in main异常
2006-09-24 20:31
快速回复:象棋一chessApp.java-->千里冰封转移
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.063480 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved