The class ChessMainFrame extends JFrame implements ActionListener, MouseListener, Runnable {
//player
JLabel play []=new JLabel [32].
//board
JLabel image;
//pane
The Container con;
//toolbar
JToolBar jmain;
//start
JButton anew;
//back
JButton repent;
//open the
JButton showOpen;
//save
JButton showSave;
//out
JButton exit;
//current information
JLabel text;
//save the current operating
The Vector FileVar;
The Vector Var.
//rule class object (used to call a method)
ChessRule rule;
/* click pieces * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* chessManClick=true flicker pieces and response to thread */
/* chessManClick=false eat piece stop flashing and response to thread */
Boolean chessManClick;
/* control the player's turn * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* chessPlayClick=1 black moves */
/* chessPlayClick=2 red flag's turn red flag by default */
/* chessPlayClick=3 both sides cannot turn red flag's turn is the default flag */
Int chessPlayClick=2;
//control piece glittering thread
Thread tmain;
//give first click to thread response
Static int Man, I;
ChessMainFrame () {
}
ChessMainFrame (String Title) {
//a reference line carved lattice
Con=this. GetContentPane ();
Con. SetLayout (null);
//instantiate the rule class
Rule=new ChessRule ();
FileVar=new Vector ();
Var=new Vector ();
//create a toolbar
Jmain=new JToolBar ();
Text=new JLabel (" welcome to the Chinese chess ");
Text. SetToolTipText (" message ");
Anew=new JButton (" new game ");
Anew. SetToolTipText (" start ");
The exit=new JButton (" quit ");
Exit. SetToolTipText (" exit this program ");
Repent=new JButton (" back ");
Repent. SetToolTipText (" return to the location of the last times ");
ShowOpen=new JButton (" open ");
ShowOpen. SetToolTipText (" before open the chess ");
ShowSave=new JButton (" save ");
ShowSave. SetToolTipText (" to save the current position ");
//add components to the toolbar
Jmain. SetLayout (new GridLayout (0, 6));
Jmain. Add (anew);
Jmain. Add (repent);
Jmain. Add (showOpen);
Jmain. Add (showSave);
Jmain. Add (exit);
Jmain. Add (text);
Jmain. SetBounds (0, 500, 450, 30);
Con. The add (jmain);
//add pieces tags
DrawChessMan ();
/* registered listeners */
Anew. AddActionListener (this);
Repent. AddActionListener (this);
Exit. AddActionListener (this);
ShowOpen. AddActionListener (this);
ShowSave. AddActionListener (this);
//registered pieces mobile monitor
for(int i=0; i<32. I++) {
DrawChessMan ();
Con. The add (play [I]);
Play [I] addMouseListener (this);
}
//add board tags
Con. The add (image=new JLabel (new ImageIcon (" CChess. GIF ")));
Image. The setBounds (0, 0, 445, 498);
Image. AddMouseListener (this);
//registration form close monitor
Enclosing addWindowListener (new WindowAdapter () {
Public void windowClosing (WindowEvent we) {
System.exit(0);
}
});
//form center
Dimension screenSize=Toolkit. GetDefaultToolkit (.) getScreenSize ();
Dimension frameSize=this. GetSize ();
If (frameSize. Height & gt; ScreenSize. Height) {
FrameSize. Height=screenSize. Height;
}
If (frameSize. Width & gt; ScreenSize. Width) {
FrameSize. Width=screenSize. Width;
}
Enclosing setLocation (screenSize. Width - frameSize. Width)/2-200 (screenSize. Height - frameSize. Height)/2-290);
Enclosing setIconImage (new ImageIcon (" phase 1. GIF "). The getImage ());
Enclosing setResizable (false);
Enclosing setTitle (Title);
Enclosing setSize (450, 555);
This. The show ();
}
/* add pieces method * * * * * * * * * * * * */
Public void drawChessMan () {
//process control
Int I, k;
//icon
Icon in;
//black pieces
//car
In=new ImageIcon (" car 1. GIF ");
For (I=0, k=10; i<2; I++, k +=385); {
Play [I]=new JLabel (in);
Play [I] setBounds (k, 10,40,40);
Play [I] elegantly-named setName (car "1");
}
//ma
In=new ImageIcon (" horse 1. GIF ");
For (I=4, k=60; i<6; I++, k +=285); {
Play [I]=new JLabel (in);
Play [I] setBounds (k, 10,40,40);
Play [I] elegantly-named setName (" horse 1 ");
}
//like
In=new ImageIcon (" like 1. GIF ");
For (I=8, k=105; i<10; I++, k +=195); {
Play [I]=new JLabel (in);
Play [I] setBounds (k, 10,40,40);
Play [I] elegantly-named setName (like "1");
}
//"
In=new ImageIcon (" and 1. GIF ");
For (I=12, k=155; i<14. I++, k +=95); {
Play [I]=new JLabel (in);
Play [I] setBounds (k, 10,40,40);
Play [I] elegantly-named setName (" "1");
}
//single
In=new ImageIcon (" pawn 1. GIF ");
For (I=16, k=10; i<21. I++, k +=96.5); {
Play [I]=new JLabel (in);
Play [I] setBounds (k, 160,40,40);
Play [I] elegantly-named setName (" pawn "1 + I);
}
//gun
In=new ImageIcon (" cannon 1. GIF ");
For (I=26 k=60; i<28; I++, k +=289); {
Play [I]=new JLabel (in);
Play [I] setBounds (k, 110,40,40);
Play [I] elegantly-named setName (" cannon 1 "+ I);
}
//will
In=new ImageIcon (" will be 1. GIF ");
Play [30]=new JLabel (in);
Play [30]. SetBounds,10,40,40 (205);
Play [30]. Elegantly-named setName (" 1 ");
//red pieces
//car
In=new ImageIcon (" cars 2. GIF ");
For (I=2 and k=10; i<4. I++, k +=385); {
Play [I]=new JLabel (in);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull