Java2实用教程(第二版)程序代码——第十八章 Java中的鼠标事件和键盘事件

  1 None.gif // 例子1
  2 None.gif import java.applet. * ;import java.awt. *
  3 None.gifimport java.awt. event . * ;
  4 None.gif public   class  Example18_1 extends Applet implements MouseListener
  5 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  TextField text;
  6InBlock.gif   public void init()
  7ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  text=new TextField(40); add(text);
  8InBlock.gif      addMouseListener(this) ;//向小程序增加鼠标事件监视器。
  9ExpandedSubBlockEnd.gif   }
   
 10InBlock.gif   public void mousePressed(MouseEvent e)
 11ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  text.setText("鼠标键按下了,位置是"+e.getX()+","+e.getY() );
 12ExpandedSubBlockEnd.gif   }
 
 13InBlock.gif   public void mouseReleased(MouseEvent e)
 14ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  text.setText(" 鼠标松开了,位置是"+e.getX()+","+e.getY() );
 15ExpandedSubBlockEnd.gif   }

 16InBlock.gif   public void mouseEntered(MouseEvent e)
 17ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  text.setText(" 鼠标进来了,位置是"+e.getX()+","+e.getY() );
 18ExpandedSubBlockEnd.gif   }

 19InBlock.gif   public void mouseExited(MouseEvent e)
 20ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  text.setText(" 鼠标走开了");
 21ExpandedSubBlockEnd.gif   }

 22InBlock.gif   public void mouseClicked(MouseEvent e)
 23ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getClickCount()==2)
 24ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  text.setText("鼠标键双击,位置:"+e.getX()+","+e.getY());
 25ExpandedSubBlockEnd.gif       }
  
 26ExpandedSubBlockStart.gifContractedSubBlock.gif      else dot.gif{}
 27ExpandedSubBlockEnd.gif   }

 28ExpandedBlockEnd.gif}

 29 None.gif
 30 None.gif // 例子2
 31 None.gif import java.awt. * ;import java.awt. event . * ;
 32 None.gif class  MyCanvas extends Canvas implements MouseListener
 33 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  int left=-1,right=-1//记录左、右键用的变量。 
 34InBlock.gif   int x=-1,y=-1;        //记录鼠标位置用的变量。
 35InBlock.gif   MyCanvas()
 36ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setSize(100,100);
 37InBlock.gif      setBackground(Color.cyan) ;
 38InBlock.gif      addMouseListener(this);
 39ExpandedSubBlockEnd.gif    }
   
 40InBlock.gif   public void paint(Graphics g)
 41ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(left==1)
 42ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  g.drawOval(x-10,y-10,20,20);
 43ExpandedSubBlockEnd.gif       }

 44InBlock.gif     else if(right==1)
 45ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  g.drawRect(x-8,y-8,16,16);
 46ExpandedSubBlockEnd.gif       }

 47ExpandedSubBlockEnd.gif   }
 
 48InBlock.gif   public void mousePressed(MouseEvent e)
 49ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  x=e.getX(); y=e.getY();
 50InBlock.gif      if(e.getModifiers()==InputEvent.BUTTON1_MASK)
 51ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  left=1;right=-1;
 52InBlock.gif           repaint();
 53ExpandedSubBlockEnd.gif        }

 54InBlock.gif      else if(e.getModifiers()==InputEvent.BUTTON3_MASK)
 55ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  right=1; left=-1;
 56InBlock.gif          repaint();
 57ExpandedSubBlockEnd.gif        }

 58ExpandedSubBlockEnd.gif   }
 
 59ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseReleased(MouseEvent e)dot.gif{}
 60ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseEntered(MouseEvent e)dot.gif{}
 61InBlock.gif   public void mouseExited(MouseEvent e)
 62ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  left=-1;right=-1;
 63InBlock.gif      repaint();
 64ExpandedSubBlockEnd.gif   }

 65ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseClicked(MouseEvent e)dot.gif{}
 66InBlock.gif   public void update(Graphics g)
 67ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(left==1||right==1)
 68ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{ paint(g);
 69ExpandedSubBlockEnd.gif        }

 70InBlock.gif      else
 71ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{ super.update(g);
 72ExpandedSubBlockEnd.gif        }

 73ExpandedSubBlockEnd.gif   }

 74ExpandedBlockEnd.gif}

 75 None.gif public   class  Example18_2 
 76 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  public static void main(String args[])
 77ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  Frame f=new Frame();
 78InBlock.gif      f.setBounds(100,100,200,200);f.setVisible(true);
 79InBlock.gif      f.addWindowListener(new WindowAdapter()  //适配器
 80ExpandedSubBlockStart.gifContractedSubBlock.gif                  dot.gif{public void windowClosing(WindowEvent e)
 81ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{System.exit(0);
 82ExpandedSubBlockEnd.gif                    }

 83ExpandedSubBlockEnd.gif                  }
);
 84InBlock.gif      f.add(new MyCanvas(),BorderLayout.CENTER);//添加画布。
 85InBlock.gif      f.validate();    
 86ExpandedSubBlockEnd.gif   }

 87ExpandedBlockEnd.gif}

 88 None.gif
 89 None.gif // 例子3
 90 None.gif import java.awt. * ;import java.awt. event . * ;
 91 None.gifimport java.applet. * ;
 92 None.gif public   class  Example18_3 extends Applet implements MouseListener 
 93 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  TextField text; Button button;
 94InBlock.gif   TextArea textArea; 
 95InBlock.gif   public void init() 
 96ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  text=new TextField(10); text.addMouseListener(this);
 97InBlock.gif      button=new Button("按钮"); button.addMouseListener(this);
 98InBlock.gif      addMouseListener(this);
 99InBlock.gif      textArea=new TextArea(8,28);
100InBlock.gif      add(button);add(text);add(textArea);
101ExpandedSubBlockEnd.gif   }

102InBlock.gif   public void mousePressed(MouseEvent e)
103ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getSource()==button)
104ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{textArea.append("\n在按钮上鼠标按下,位置:"+"("+e.getX()+","+e.getY()+")");
105ExpandedSubBlockEnd.gif      }

106InBlock.gif     else if(e.getSource()==text)
107ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{textArea.append("\n在文本框上鼠标按下,位置:"+"("+e.getX()+","+e.getY()+")");
108ExpandedSubBlockEnd.gif      }

109InBlock.gif    else if(e.getSource()==this)
110ExpandedSubBlockStart.gifContractedSubBlock.gif     dot.gif{textArea.append("\n在容器上鼠标按下,位置:"+"("+e.getX()+","+e.getY()+")");
111ExpandedSubBlockEnd.gif     }
 
112ExpandedSubBlockEnd.gif   }

113ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseReleased(MouseEvent e) dot.gif{}
114ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseEntered(MouseEvent e)  dot.gif{}
115ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseExited(MouseEvent e) dot.gif{}
116InBlock.gif   public void mouseClicked(MouseEvent e) 
117ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getClickCount()>=2)
118InBlock.gif      textArea.setText("鼠标连击,位置:"+"("+e.getX()+","+e.getY()+")");
119ExpandedSubBlockEnd.gif   }

120ExpandedBlockEnd.gif}

121 None.gif
122 None.gif // 例子4 
123 None.gif import java.applet. * ;import java.awt. * ;import java.awt. event . * ;
124 None.gif public   class  Example18_4 extends Applet implements MouseMotionListener
125 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  int x=-1,y=-1;
126InBlock.gif   public void init()
127ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setBackground(Color.green);
128InBlock.gif      addMouseMotionListener(this); 
129ExpandedSubBlockEnd.gif   }

130InBlock.gif   public void paint(Graphics g)
131ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(x!=-1&&y!=-1)
132ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  g.setColor(Color.red);
133InBlock.gif          g.drawLine(x,y,x,y);
134ExpandedSubBlockEnd.gif       }

135ExpandedSubBlockEnd.gif   }

136InBlock.gif   public void mouseDragged(MouseEvent e)
137ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  x=(int)e.getX();y=(int)e.getY();
138InBlock.gif      repaint();
139ExpandedSubBlockEnd.gif    }

140ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseMoved(MouseEvent e)dot.gif{} 
141InBlock.gif   public void update(Graphics g)
142ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  paint(g);
143ExpandedSubBlockEnd.gif   }
 
144ExpandedBlockEnd.gif}

145 None.gif
146 None.gif // 例子5 
147 None.gif import java.applet. * ;import java.awt. * ;
148 None.gifimport java.awt. event . * ;
149 None.gif public   class  Example18_5 extends Applet
150 None.gifimplements ActionListener,MouseMotionListener
151 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  int x=-1,y=-1,橡皮擦通知=0,清除通知=0;
152InBlock.gif   Color c=new Color(255,0,0);int con=3;
153InBlock.gif   Button b_red,b_blue,b_green,
154InBlock.gif   清除,b_quit;
155InBlock.gif   public void init()
156ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  addMouseMotionListener(this); 
157InBlock.gif      b_red=new Button("画红色图形");    
158InBlock.gif      b_blue=new Button("兰色图形"); 
159InBlock.gif      b_green=new Button("画绿色图形");  
160InBlock.gif      b_quit=new Button("橡皮");
161InBlock.gif      清除=new Button("清除");
162InBlock.gif      add(b_red); add(b_green); add(b_blue); add(b_quit);add(清除);
163InBlock.gif      b_red.addActionListener(this); b_green.addActionListener(this);
164InBlock.gif      b_blue.addActionListener(this); b_quit.addActionListener(this);
165InBlock.gif      清除.addActionListener(this);
166ExpandedSubBlockEnd.gif   }

167InBlock.gif   public void paint(Graphics g)
168ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(x!=-1&&y!=-1&&橡皮擦通知==0&&清除通知==0)
169ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{  g.setColor(c); g.fillOval(x,y,con,con);
170ExpandedSubBlockEnd.gif         }

171InBlock.gif       else if(橡皮擦通知==1&&清除通知==0)
172ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  g.clearRect(x,y,10,10);
173ExpandedSubBlockEnd.gif        }

174InBlock.gif       else if(清除通知==1&&橡皮擦通知==0)
175ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  g.clearRect(0,0,getSize().width,getSize().height);
176ExpandedSubBlockEnd.gif        }

177ExpandedSubBlockEnd.gif   }

178InBlock.gif   public void mouseDragged(MouseEvent e)
179ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  x=(int)e.getX();y=(int)e.getY(); repaint();
180ExpandedSubBlockEnd.gif   }

181ExpandedSubBlockStart.gifContractedSubBlock.gif    public void mouseMoved(MouseEvent e)dot.gif{ } 
182InBlock.gif   public void update(Graphics g)
183ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  paint(g);
184ExpandedSubBlockEnd.gif   }
 
185InBlock.gif   public void actionPerformed(ActionEvent e)
186ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getSource()==b_red)
187ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  橡皮擦通知=0;清除通知=0; c=new Color(255,0,0);
188ExpandedSubBlockEnd.gif        }

189InBlock.gif      else if(e.getSource()==b_green)
190ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  橡皮擦通知=0;清除通知=0;  c=new Color(0,255,0);
191ExpandedSubBlockEnd.gif        }

192InBlock.gif      else if(e.getSource()==b_blue)
193ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  橡皮擦通知=0;清除通知=0; c=new Color(0,0,255);
194ExpandedSubBlockEnd.gif        }

195InBlock.gif      if(e.getSource()==b_quit)
196ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{   橡皮擦通知=1;清除通知=0 ;
197ExpandedSubBlockEnd.gif       }

198InBlock.gif      if(e.getSource()==清除)
199ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{   清除通知=1; 橡皮擦通知=0;repaint();
200ExpandedSubBlockEnd.gif       }

201ExpandedSubBlockEnd.gif   }

202ExpandedBlockEnd.gif}

203 None.gif
204 None.gif // 例子6
205 None.gif import java.awt. * ;import java.awt. event . * ;import java.applet. *
206 None.gifimport javax.swing.SwingUtilities;
207 None.gif public   class  Example18_6 extends Frame implements MouseListener,MouseMotionListener
208 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  Button button;
209InBlock.gif   int x,y;
210InBlock.gif   boolean move=false;
211InBlock.gif   Example18_6()
212ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  button=new Button("按钮"); 
213InBlock.gif      button.addMouseListener(this);
214InBlock.gif      button.addMouseMotionListener(this);
215InBlock.gif      addMouseMotionListener(this);
216InBlock.gif      setLayout(new FlowLayout());
217InBlock.gif      add(button);
218InBlock.gif      addWindowListener(new WindowAdapter()
219ExpandedSubBlockStart.gifContractedSubBlock.gif              dot.gif{   public void windowClosing(WindowEvent e)
220ExpandedSubBlockStart.gifContractedSubBlock.gif                  dot.gif{ System.exit(0);
221ExpandedSubBlockEnd.gif                  }

222ExpandedSubBlockEnd.gif              }
);
223InBlock.gif      setBounds(10,10,200,180);
224InBlock.gif      setVisible(true); validate();
225ExpandedSubBlockEnd.gif   }

226ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mousePressed(MouseEvent e) dot.gif{}
227InBlock.gif   public void mouseReleased(MouseEvent e)
228ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  move=false;
229ExpandedSubBlockEnd.gif   }

230ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseEntered(MouseEvent e)  dot.gif{}
231ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseExited(MouseEvent e) dot.gif{}
232ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseClicked(MouseEvent e)dot.gif{}
233ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseMoved(MouseEvent e)dot.gif{} 
234InBlock.gif   public void mouseDragged(MouseEvent e)
235ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  Button b=null;
236InBlock.gif      if(e.getSource() instanceof Button) //在按钮上拖动鼠标导致按钮上发生鼠标事件。
237ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{ b=(Button)e.getSource();   
238InBlock.gif           move=true
239InBlock.gif          //将鼠标拖动事件转移到棋盘,导致棋盘上发生鼠标拖动事件:
240InBlock.gif          e=SwingUtilities.convertMouseEvent(button,e,this);
241InBlock.gif          //并将从按钮转移得到的鼠标事件e传递给mouseDragged方法的参数。
242ExpandedSubBlockEnd.gif         }

243InBlock.gif      if(e.getSource()==this)
244ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{  if(move&&b!=null)
245ExpandedSubBlockStart.gifContractedSubBlock.gif              dot.gif{  x=e.getX(); y=e.getY();
246InBlock.gif                 int w=b.getSize().width,h=b.getSize().height;
247InBlock.gif                  b.setLocation(x-w/2,y-h/2);
248ExpandedSubBlockEnd.gif               }

249ExpandedSubBlockEnd.gif           }

250ExpandedSubBlockEnd.gif   }

251InBlock.gif   public static void main(String args[])
252ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  new Example18_6();
253ExpandedSubBlockEnd.gif   }

254ExpandedBlockEnd.gif}

255 None.gif
256 None.gif // 例子7
257 None.gif import java.applet. * ;import java.awt. * ;
258 None.gifimport java.awt. event . * ;
259 None.gif public   class  Example18_7 extends Applet implements
260 None.gifKeyListener
261 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  Button b[]=new Button[10];
262InBlock.gif   int x,y;
263InBlock.gif   public void init()
264ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  for(int i=0;i<=9;i++
265ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{  b[i]=new Button(""+i);
266InBlock.gif            b[i].addKeyListener(this);
267InBlock.gif            add(b[i]);
268ExpandedSubBlockEnd.gif         }

269ExpandedSubBlockEnd.gif   }

270InBlock.gif   public void keyPressed(KeyEvent e)
271ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  Button button=(Button)e.getSource();
272InBlock.gif      x=button.getBounds().x;
273InBlock.gif      y=button.getBounds().y;
274InBlock.gif      if(e.getKeyCode()==KeyEvent.VK_UP)
275ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  y=y-2;
276InBlock.gif           if(y<=0) y=0;
277InBlock.gif           button.setLocation(x,y);
278ExpandedSubBlockEnd.gif        }

279InBlock.gif      else if(e.getKeyCode()==KeyEvent.VK_DOWN)
280ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  y=y+2;
281InBlock.gif          if(y>=300) y=300
282InBlock.gif          button.setLocation(x,y);
283ExpandedSubBlockEnd.gif       }

284InBlock.gif      else if(e.getKeyCode()==KeyEvent.VK_LEFT)
285ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  x=x-2;
286InBlock.gif          if(x<=0) x=0;
287InBlock.gif          button.setLocation(x,y);
288ExpandedSubBlockEnd.gif       }
 
289InBlock.gif      else if(e.getKeyCode()==KeyEvent.VK_RIGHT)
290ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  x=x+2;
291InBlock.gif          if(x>=300) x=300;
292InBlock.gif          button.setLocation(x,y);
293ExpandedSubBlockEnd.gif       }

294ExpandedSubBlockEnd.gif   }

295ExpandedSubBlockStart.gifContractedSubBlock.gif   public void keyTyped(KeyEvent e) dot.gif{}
296ExpandedSubBlockStart.gifContractedSubBlock.gif   public void keyReleased(KeyEvent e) dot.gif{}
297ExpandedBlockEnd.gif}

298 None.gif
299 None.gif // 例子8
300 None.gif import java.awt. * ;import java.awt. event . * ;
301 None.gif // 创建棋盘的类:
302 None.gif class  ChessPad extends Panel  implements MouseListener,ActionListener
303 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  int x=-1,y=-1, 棋子颜色=1;               //控制棋子颜色的成员变量。
304InBlock.gif   Button button=new Button("重新开局");    //控制重新开局的按扭。
305InBlock.gif   TextField text_1=new TextField("请黑棋下子"),
306InBlock.gif             text_2=new TextField();              //提示下棋的两个文本框。
307InBlock.gif   ChessPad()
308ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setSize(440,440);
309InBlock.gif      setLayout(null);setBackground(Color.pink);
310InBlock.gif      addMouseListener(this);add(button);button.setBounds(10,5,60,26);
311InBlock.gif      button.addActionListener(this);
312InBlock.gif      add(text_1);text_1.setBounds(90,5,90,24);
313InBlock.gif      add(text_2);text_2.setBounds(290,5,90,24);
314InBlock.gif      text_1.setEditable(false);text_2.setEditable(false);
315ExpandedSubBlockEnd.gif   }

316InBlock.gif   public void paint(Graphics g)                    //绘制围棋棋盘的外观。
317ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  for(int i=40;i<=380;i=i+20)
318ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  g.drawLine(40,i,400,i);
319ExpandedSubBlockEnd.gif       }

320InBlock.gif      g.drawLine(40,400,400,400);
321InBlock.gif      for(int j=40;j<=380;j=j+20)
322ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{ g.drawLine(j,40,j,400);
323ExpandedSubBlockEnd.gif       }

324InBlock.gif       g.drawLine(400,40,400,400); 
325InBlock.gif       g.fillOval(97,97,6,6); g.fillOval(337,97,6,6);
326InBlock.gif       g.fillOval(97,337,6,6);g.fillOval(337,337,6,6);
327InBlock.gif       g.fillOval(217,217,6,6);
328ExpandedSubBlockEnd.gif   }

329InBlock.gif   public void mousePressed(MouseEvent e)     //当按下鼠标左键时下棋子。
330ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getModifiers()==InputEvent.BUTTON1_MASK)
331ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  x=(int)e.getX();y=(int)e.getY();      //获取按下鼠标时的坐标位置。
332InBlock.gif           ChessPoint_black chesspoint_black=new ChessPoint_black(this);
333InBlock.gif           ChessPoint_white chesspoint_white=new ChessPoint_white(this);
334InBlock.gif           int a=(x+10)/20,b=(y+10)/20;
335InBlock.gif           if(x/20<2||y/20<2||x/20>19||y/20>19)    //棋盘以外不下棋子。
336ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{}
337InBlock.gif           else
338ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif
339InBlock.gif              if(棋子颜色==1)                       //当棋子颜色是1时下黑棋子。
340ExpandedSubBlockStart.gifContractedSubBlock.gif               dot.gif{  this.add(chesspoint_black);
341InBlock.gif                  chesspoint_black.setBounds(a*20-7,b*20-7,16,16);
342InBlock.gif                  棋子颜色=棋子颜色*(-1);             
343InBlock.gif                  text_2.setText("请白棋下子");
344InBlock.gif                  text_1.setText("");
345ExpandedSubBlockEnd.gif               }

346InBlock.gif              else if(棋子颜色==-1)                   //当棋子颜色是-1时下白棋子。
347ExpandedSubBlockStart.gifContractedSubBlock.gif               dot.gif{  this.add(chesspoint_white);
348InBlock.gif                  chesspoint_white.setBounds(a*20-7,b*20-7,16,16);
349InBlock.gif                   棋子颜色=棋子颜色*(-1);
350InBlock.gif                  text_1.setText("请黑棋下子");
351InBlock.gif                  text_2.setText("");
352ExpandedSubBlockEnd.gif               }

353ExpandedSubBlockEnd.gif            }

354ExpandedSubBlockEnd.gif       }

355ExpandedSubBlockEnd.gif   }

356ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseReleased(MouseEvent e)dot.gif{}
357ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseEntered(MouseEvent e) dot.gif{}
358ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseExited(MouseEvent e) dot.gif{}
359ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseClicked(MouseEvent e)dot.gif{}
360InBlock.gif   public void actionPerformed(ActionEvent e)
361ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  this.removeAll();棋子颜色=1;
362InBlock.gif      add(button);button.setBounds(10,5,60,26);
363InBlock.gif      add(text_1);text_1.setBounds(90,5,90,24);  
364InBlock.gif      text_2.setText("");text_1.setText("请黑棋下子");
365InBlock.gif      add(text_2);text_2.setBounds(290,5,90,24);
366ExpandedSubBlockEnd.gif   }

367ExpandedBlockEnd.gif}

368 None.gif // 负责创建黑色棋子的类:
369 None.gif class  ChessPoint_black extends Canvas implements MouseListener
370 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  ChessPad chesspad=null;                        //棋子所在的棋盘。
371InBlock.gif   ChessPoint_black(ChessPad p)
372ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setSize(20,20);chesspad=p; addMouseListener(this);
373ExpandedSubBlockEnd.gif   }

374InBlock.gif   public void paint(Graphics g)         //绘制棋子的大小。
375ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  g.setColor(Color.black);g.fillOval(0,0,14,14);
376ExpandedSubBlockEnd.gif   }
 
377InBlock.gif   public void mousePressed(MouseEvent e) 
378ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getModifiers()==InputEvent.BUTTON3_MASK)
379ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  chesspad.remove(this);//当用鼠标右键点击棋子时,从棋盘中去掉该棋子(悔棋)。
380InBlock.gif          chesspad.棋子颜色=1;
381InBlock.gif          chesspad.text_2.setText("");chesspad.text_1.setText("请黑棋下子");
382ExpandedSubBlockEnd.gif        }

383ExpandedSubBlockEnd.gif   }

384ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseReleased(MouseEvent e)dot.gif{}
385ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseEntered(MouseEvent e) dot.gif{}
386ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseExited(MouseEvent e) dot.gif{}
387InBlock.gif   public void mouseClicked(MouseEvent e)
388ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getClickCount()>=2)
389InBlock.gif         chesspad.remove(this);             //当用左键双击该棋子时,吃掉该棋子。
390ExpandedSubBlockEnd.gif   }

391ExpandedBlockEnd.gif}

392 None.gif // 负责创建白色棋子的类:
393 None.gif class  ChessPoint_white extends Canvas implements MouseListener
394 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  ChessPad chesspad=null;
395InBlock.gif   ChessPoint_white(ChessPad p)
396ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setSize(20,20);addMouseListener(this);
397InBlock.gif      chesspad=p; 
398ExpandedSubBlockEnd.gif   }

399InBlock.gif   public void paint(Graphics g)
400ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  g.setColor(Color.white);g.fillOval(0,0,14,14); 
401ExpandedSubBlockEnd.gif   }
 
402InBlock.gif   public void mousePressed(MouseEvent e)
403ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getModifiers()==InputEvent.BUTTON3_MASK)
404ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  chesspad.remove(this);chesspad.棋子颜色=-1;
405InBlock.gif           chesspad.text_2.setText("请白棋下子"); chesspad.text_1.setText("");
406ExpandedSubBlockEnd.gif        }

407ExpandedSubBlockEnd.gif   }

408ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseReleased(MouseEvent e)dot.gif{}
409ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseEntered(MouseEvent e) dot.gif{}
410ExpandedSubBlockStart.gifContractedSubBlock.gif   public void mouseExited(MouseEvent e) dot.gif{}
411InBlock.gif   public void mouseClicked(MouseEvent e)
412ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  if(e.getClickCount()>=2)
413InBlock.gif         chesspad.remove(this);
414ExpandedSubBlockEnd.gif   }

415ExpandedBlockEnd.gif}

416 None.gif public   class  Chess extends Frame   // 添加棋盘的窗口。
417 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  ChessPad chesspad=new ChessPad();
418InBlock.gif   Chess()
419ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setVisible(true);
420InBlock.gif      setLayout(null);
421InBlock.gif    Label label=
422InBlock.gif    new Label("单击左键下棋子,双击吃棋子,用右键单击棋子悔棋",Label.CENTER);
423InBlock.gif      add(label);label.setBounds(70,55,440,26);
424InBlock.gif      label.setBackground(Color.orange); 
425InBlock.gif      add(chesspad);chesspad.setBounds(70,90,440,440);
426InBlock.gif      addWindowListener(new WindowAdapter()
427ExpandedSubBlockStart.gifContractedSubBlock.gif                 dot.gif{public void windowClosing(WindowEvent e)
428ExpandedSubBlockStart.gifContractedSubBlock.gif                         dot.gif{System.exit(0);
429ExpandedSubBlockEnd.gif                         }

430ExpandedSubBlockEnd.gif             }
);
431InBlock.gif     pack();setSize(600,550);
432ExpandedSubBlockEnd.gif   }

433InBlock.gifpublic static void main(String args[])
434ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  Chess chess=new Chess();
435ExpandedSubBlockEnd.gif   }

436ExpandedBlockEnd.gif}

437 None.gif
438 None.gif // 例子9
439 None.gif import java.awt. event . * ;import java.applet. * ;
440 None.gifimport java.awt. * ;
441 None.gif public   class  Move extends.Applet implements KeyListener,ActionListener
442 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  Button b_go=new Button("go"),
443InBlock.gif   b_replay=new Button("replay");
444InBlock.gif   Rectangle rect1,rect2,rect3;
445InBlock.gif   int b_x=0,b_y=0;
446InBlock.gif   public void init()
447ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  b_go.addKeyListener(this);
448InBlock.gif      b_replay.addActionListener(this);
449InBlock.gif      setLayout(null);
450InBlock.gif      //代表迷宫的矩形:
451InBlock.gif      rect1=new Rectangle(20,40,200,40);
452InBlock.gif      rect2=new Rectangle(200,40,24,240);
453InBlock.gif      rect3=new Rectangle(200,220,100,40);
454InBlock.gif      b_go.setBackground(Color.red);      //代表走迷宫者的按扭。 
455InBlock.gif      add(b_go);b_go.setBounds(22,45,20,20);
456InBlock.gif      b_x=b_go.getBounds().x;b_y=b_go.getBounds().y;
457InBlock.gif      b_go.requestFocus() ;
458InBlock.gif      add(b_replay);b_replay.setBounds(2,2,45,16);//点击重新开始的按扭。   
459ExpandedSubBlockEnd.gif   }

460InBlock.gif   public void paint(Graphics g)
461ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  //画出迷宫:
462InBlock.gif      g.setColor(Color.green);
463InBlock.gif      g.fillRect(20,40,200,40);
464InBlock.gif      g.setColor(Color.yellow);
465InBlock.gif      g.fillRect(200,40,40,240);
466InBlock.gif      g.setColor(Color.cyan);
467InBlock.gif      g.fillRect(200,220,100,40);
468InBlock.gif      g.drawString("出口",310,220);
469InBlock.gif      g.setColor(Color.black);
470InBlock.gif      g.drawString("点击红色按扭,然后用键盘上的方向键移动按扭",100,20);
471ExpandedSubBlockEnd.gif   }

472InBlock.gif   public void keyPressed(KeyEvent e)
473ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  //按键盘上的上下、左右键在迷宫中行走:
474InBlock.gif      if((e.getKeyCode()==KeyEvent.VK_UP))
475ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif//创建一个和按扭:b_go 同样大小的矩形:
476InBlock.gif          Rectangle rect=new Rectangle(b_x,b_y,20,20);
477InBlock.gif         //要求必须在迷宫内行走:
478InBlock.gif           if(rect.intersects(rect1)||rect.intersects(rect2)||
479InBlock.gifrect.intersects(rect3))
480ExpandedSubBlockStart.gifContractedSubBlock.gif             dot.gif{  b_y=b_y-2;b_go.setLocation(b_x,b_y);
481ExpandedSubBlockEnd.gif             }

482ExpandedSubBlockEnd.gif         }

483InBlock.gif       else if(e.getKeyCode()==KeyEvent.VK_DOWN)
484ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{  Rectangle rect=new Rectangle(b_x,b_y,20,20);
485InBlock.gif            if(rect.intersects(rect1)||rect.intersects(rect2)||
486InBlock.gifrect.intersects(rect3))
487ExpandedSubBlockStart.gifContractedSubBlock.gif             dot.gif{ b_y=b_y+2;b_go.setLocation(b_x,b_y);
488ExpandedSubBlockEnd.gif             }

489ExpandedSubBlockEnd.gif         }

490InBlock.gif       else if(e.getKeyCode()==KeyEvent.VK_LEFT)
491ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{  Rectangle rect=new Rectangle(b_x,b_y,20,20);
492InBlock.gif            if(rect.intersects(rect1)||rect.intersects(rect2)
493InBlock.gif||rect.intersects(rect3))
494ExpandedSubBlockStart.gifContractedSubBlock.gif             dot.gif{  b_x=b_x-2;b_go.setLocation(b_x,b_y);
495ExpandedSubBlockEnd.gif             }
 
496ExpandedSubBlockEnd.gif          }
 
497InBlock.gif      else if(e.getKeyCode()==KeyEvent.VK_RIGHT)
498ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{  Rectangle rect=new Rectangle(b_x,b_y,20,20);
499InBlock.gif           if(rect.intersects(rect1)||rect.intersects(rect2)||
500InBlock.gifrect.intersects(rect3))
501ExpandedSubBlockStart.gifContractedSubBlock.gif              dot.gif{ b_x=b_x+2;b_go.setLocation(b_x,b_y);
502ExpandedSubBlockEnd.gif              }

503ExpandedSubBlockEnd.gif      }

504ExpandedSubBlockEnd.gif   }

505ExpandedSubBlockStart.gifContractedSubBlock.gif   public void keyReleased(KeyEvent e)dot.gif{}
506ExpandedSubBlockStart.gifContractedSubBlock.gif   public void keyTyped(KeyEvent e)dot.gif{}
507InBlock.gif   public void actionPerformed(ActionEvent e)
508ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  b_go.setBounds(22,45,20,20); 
509InBlock.gif  b_x=b_go.getBounds().x;b_y=b_go.getBounds().y;
510InBlock.gif  b_go.requestFocus() ;
511ExpandedSubBlockEnd.gif }
 
512ExpandedBlockEnd.gif}

513 None.gif
514 None.gif // 例子10
515 None.gif import java.awt. * ;import java.applet. * ;import java.awt. event . * ;
516 None.gif class  People extends Button implements FocusListener   // 代表华容道人物的类。
517 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  Rectangle rect=null;
518InBlock.gif   int left_x,left_y;//按扭的左上角坐标.
519InBlock.gif   int width,height; //按扭的宽和高.
520InBlock.gif   String name; int number;
521InBlock.gif   People(int number,String s,int x,int y,int w,int h,Hua_Rong_Road road)
522ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  super(s);
523InBlock.gif      name=s;this.number=number;
524InBlock.gif      left_x=x;left_y=y;
525InBlock.gif      width=w;height=h;setBackground(Color.orange);
526InBlock.gif      road.add(this);    addKeyListener(road);
527InBlock.gif      setBounds(x,y,w,h);addFocusListener(this);
528InBlock.gif      rect=new Rectangle(x,y,w,h);
529ExpandedSubBlockEnd.gif   }

530InBlock.gif   public void focusGained(FocusEvent e)
531ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setBackground(Color.red);
532ExpandedSubBlockEnd.gif   }

533InBlock.gif   public void focusLost(FocusEvent e)
534ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{   setBackground(Color.orange);
535ExpandedSubBlockEnd.gif   }

536ExpandedBlockEnd.gif}

537 None.gif public   class  Hua_Rong_Road extends Applet implements KeyListener,ActionListener
538 ExpandedBlockStart.gifContractedBlock.gif dot.gif {  People people[]=new People[10];
539InBlock.gif   Rectangle left,right,above ,below;//华容道的边界 .
540InBlock.gif   Button restart=new Button("重新开始");   
541InBlock.gif   public void init()
542ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  setLayout(null); add(restart);
543InBlock.gif      restart.setBounds(5,5,80,25);
544InBlock.gif      restart.addActionListener(this);
545InBlock.gif      people[0]=new People(0,"曹操",104,54,100,100,this); 
546InBlock.gif      people[1]=new People(1,"关羽",104,154,100,50,this); 
547InBlock.gif      people[2]=new People(2,"张飞",54154,50,100,this); 
548InBlock.gif    people[3]=new People(3,"刘备",204,154,50,100,this); 
549InBlock.gif    people[4]=new People(4,"张辽",545450,100,this); 
550InBlock.gif    people[5]=new People(5,"曹仁",2045450,100,this);  
551InBlock.gif    people[6]=new People(6,"兵  ",54,254,50,50,this);  
552InBlock.gif    people[7]=new People(7,"兵  ",204,254,50,50,this); 
553InBlock.gif    people[8]=new People(8,"兵  ",104,204,50,50,this); 
554InBlock.gif    people[9]=new People(9,"兵  ",154,204,50,50,this); 
555InBlock.gif    people[9].requestFocus();
556InBlock.gif    left=new Rectangle(49,49,5,260);
557InBlock.gif  people[0].setForeground(Color.white) ;   
558InBlock.gif    right=new Rectangle(254,49,5,260);
559InBlock.gif      above=new Rectangle(49,49,210,5);
560InBlock.gif      below=new Rectangle(49,304,210,5);
561ExpandedSubBlockEnd.gif   }

562InBlock.gif   public void paint(Graphics g)
563ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  //画出华容道的边界:
564InBlock.gif      g.setColor(Color.cyan);
565InBlock.gif      g.fillRect(49,49,5,260);//left.
566InBlock.gif      g.fillRect(254,49,5,260);//right.
567InBlock.gif      g.fillRect(49,49,210,5); //above.
568InBlock.gif      g.fillRect(49,304,210,5);//below.
569InBlock.gif      //提示曹操逃出位置和按键规则:
570InBlock.gif      g.drawString("点击相应的人物,然后按键盘上的上下左右箭头移动",100,20);
571InBlock.gif      g.setColor(Color.red);
572InBlock.gif      g.drawString("曹操到达该位置",110,300);
573ExpandedSubBlockEnd.gif   }

574InBlock.gif   public void keyPressed(KeyEvent e) 
575ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  People man=(People)e.getSource();//获取事件源.
576InBlock.gif       man.rect.setLocation(man.getBounds().x, man.getBounds().y);
577InBlock.gif       if(e.getKeyCode()==KeyEvent.VK_DOWN)
578ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{  man.left_y=man.left_y+50;     //向下前进50个单位。
579InBlock.gif            man.setLocation(man.left_x,man.left_y);
580InBlock.gif            man.rect.setLocation(man.left_x,man.left_y);
581InBlock.gif              //判断是否和其它人物或下边界出现重叠,如果出现重叠就退回50个单位距离。       
582InBlock.gif            for(int i=0;i<10;i++)
583ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{if((man.rect.intersects(people[i].rect))&&(man.number!=i))
584ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{  man.left_y=man.left_y-50;
585InBlock.gif                       man.setLocation(man.left_x,man.left_y);
586InBlock.gif                       man.rect.setLocation(man.left_x,man.left_y);   
587ExpandedSubBlockEnd.gif                    }

588ExpandedSubBlockEnd.gif                 }

589InBlock.gif             if(man.rect.intersects(below))
590ExpandedSubBlockStart.gifContractedSubBlock.gif                 dot.gif{  man.left_y=man.left_y-50;
591InBlock.gif                    man.setLocation(man.left_x,man.left_y);
592InBlock.gif                    man.rect.setLocation(man.left_x,man.left_y); 
593ExpandedSubBlockEnd.gif                 }
 
594ExpandedSubBlockEnd.gif         }

595InBlock.gif       if(e.getKeyCode()==KeyEvent.VK_UP)
596ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  man.left_y=man.left_y-50;     //向上前进50个单位。
597InBlock.gif           man.setLocation(man.left_x,man.left_y);
598InBlock.gif           man.rect.setLocation(man.left_x,man.left_y);
599InBlock.gif           //判断是否和其它人物或上边界出现重叠,如果出现重叠就退回50个单位距离。 
600InBlock.gif           for(int i=0;i<10;i++)
601ExpandedSubBlockStart.gifContractedSubBlock.gif               dot.gif{  if((man.rect.intersects(people[i].rect))&&(man.number!=i))
602ExpandedSubBlockStart.gifContractedSubBlock.gif                      dot.gif{  man.left_y=man.left_y+50;
603InBlock.gif                         man.setLocation(man.left_x,man.left_y);
604InBlock.gif                          man.rect.setLocation(man.left_x,man.left_y);   
605ExpandedSubBlockEnd.gif                       }

606ExpandedSubBlockEnd.gif               }

607InBlock.gif            if(man.rect.intersects(above))
608ExpandedSubBlockStart.gifContractedSubBlock.gif               dot.gif{  man.left_y=man.left_y+50;
609InBlock.gif                  man.setLocation(man.left_x,man.left_y);
610InBlock.gif                  man.rect.setLocation(man.left_x,man.left_y); 
611ExpandedSubBlockEnd.gif               }
 
612ExpandedSubBlockEnd.gif        }

613InBlock.gif      if(e.getKeyCode()==KeyEvent.VK_LEFT)
614ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  man.left_x=man.left_x-50;     //向左前进50个单位。
615InBlock.gif           man.setLocation(man.left_x,man.left_y);
616InBlock.gif           man.rect.setLocation(man.left_x,man.left_y);
617InBlock.gif           //判断是否和其它人物或左边界出现重叠,如果出现重叠就退回50个单位距离。
618InBlock.gif          for(int i=0;i<10;i++)
619ExpandedSubBlockStart.gifContractedSubBlock.gif               dot.gif{  if((man.rect.intersects(people[i].rect))&&(man.number!=i))
620ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{ man.left_x=man.left_x+50;
621InBlock.gif                      man.setLocation(man.left_x,man.left_y);
622InBlock.gif                      man.rect.setLocation(man.left_x,man.left_y);   
623ExpandedSubBlockEnd.gif                     }

624ExpandedSubBlockEnd.gif               }

625InBlock.gif          if(man.rect.intersects(left))
626ExpandedSubBlockStart.gifContractedSubBlock.gif              dot.gif{  man.left_x=man.left_x+50;
627InBlock.gif                 man.setLocation(man.left_x,man.left_y);
628InBlock.gif                 man.rect.setLocation(man.left_x,man.left_y); 
629ExpandedSubBlockEnd.gif               }
 
630ExpandedSubBlockEnd.gif        }

631InBlock.gif      if(e.getKeyCode()==KeyEvent.VK_RIGHT)
632ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{  man.left_x=man.left_x+50;     //向右前进50个单位。
633InBlock.gif          man.setLocation(man.left_x,man.left_y);
634InBlock.gif          man.rect.setLocation(man.left_x,man.left_y);
635InBlock.gif         //判断是否和其它人物或右边界出现重叠,如果出现重叠就退回50个单位距离。
636InBlock.gif          for(int i=0;i<10;i++)
637ExpandedSubBlockStart.gifContractedSubBlock.gif              dot.gif{  if((man.rect.intersects(people[i].rect))&&(man.number!=i))
638ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{ man.left_x=man.left_x-50;
639InBlock.gif                      man.setLocation(man.left_x,man.left_y);
640InBlock.gif                      man.rect.setLocation(man.left_x,man.left_y);   
641ExpandedSubBlockEnd.gif                     }

642ExpandedSubBlockEnd.gif               }

643InBlock.gif           if(man.rect.intersects(right))
644ExpandedSubBlockStart.gifContractedSubBlock.gif               dot.gif{  man.left_x=man.left_x-50;
645InBlock.gif                  man.setLocation(man.left_x,man.left_y);
646InBlock.gif                  man.rect.setLocation(man.left_x,man.left_y); 
647ExpandedSubBlockEnd.gif                }
 
648ExpandedSubBlockEnd.gif         }

649ExpandedSubBlockEnd.gif   }

650ExpandedSubBlockStart.gifContractedSubBlock.gif   public void keyTyped(KeyEvent e)dot.gif{}
651ExpandedSubBlockStart.gifContractedSubBlock.gif   public void keyReleased(KeyEvent e)dot.gif{}
652InBlock.gif   public void actionPerformed(ActionEvent e)
653ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{  this.removeAll();
654InBlock.gif      this.init();
655ExpandedSubBlockEnd.gif   }
 
656ExpandedBlockEnd.gif}

657 None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值