当前位置: 代码迷 >> Java相关 >> 象棋一chessApp.java-->千里冰封转移
  详细解决方案

象棋一chessApp.java-->千里冰封转移

热度:271   发布时间:2006-04-11 12:25:00.0
象棋一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  

----------------解决方案--------------------------------------------------------
好东西~~~
----------------解决方案--------------------------------------------------------
发错地方啊,这种帖子应该发到J2SE版去
----------------解决方案--------------------------------------------------------
为什么我编译通过后,在运行的时候出来这个
[IMG]G:\Documents and Settings\jch\My Documents\11.jpg[/IMG]
----------------解决方案--------------------------------------------------------
出来什么,看不到
----------------解决方案--------------------------------------------------------
编译可以通过,不过抛出EXCEPTION in main异常
----------------解决方案--------------------------------------------------------
  相关解决方案