コード例 #1
0
 public void mouseDragged(MouseEvent e) {
   if (m_draggedFrom != Chess.NO_SQUARE) {
     m_draggedX = e.getX();
     m_draggedY = e.getY();
     repaint();
   }
 }
コード例 #2
0
 public void mousePressed(MouseEvent e) {
   if (m_positionMotionListener == null) return;
   m_draggedFrom = getSquareForEvent(e);
   if (m_positionMotionListener.allowDrag(m_position, m_draggedFrom)) {
     m_draggedStone = m_position.getStone(m_draggedFrom);
     m_draggedX = e.getX();
     m_draggedY = e.getY();
     m_draggedPartnerSqi = m_positionMotionListener.getPartnerSqi(m_position, m_draggedFrom);
     // TODO mark m_draggedPartnerSqi
     repaint();
   } else {
     m_positionMotionListener.squareClicked(m_position, m_draggedFrom, e);
     m_draggedFrom = Chess.NO_SQUARE;
   }
 }
コード例 #3
0
 private int getSquareForEvent(MouseEvent evt) {
   int size = getFont().getSize();
   return (m_bottom == Chess.WHITE
       ? Chess.coorToSqi(evt.getX() / size, Chess.NUM_OF_ROWS - evt.getY() / size - 1)
       : Chess.coorToSqi(Chess.NUM_OF_COLS - evt.getX() / size, evt.getY() / size - 1));
 }