📄 mymouselistener.java
字号:
/**
*
*/
package server;
/**
* @author Justok
*
*/
public class MyMouseListener extends java.awt.event.MouseAdapter// implements java.awt.event.MouseListener
{
public static int chesson = 0;
public static java.awt.Point pt = new java.awt.Point(-1, -1);
public static java.awt.Point prept = new java.awt.Point(-1, -1);
public void mouseDragged(java.awt.event.MouseEvent e)
{
System.err.println("md_movePath("+chesson+" , "+(e.getPoint()).x+" , "+(e.getPoint()).y+" )");
MessageProcess.md_movePath(chesson, (e.getPoint()).x,(e.getPoint()).y);
}
public void mouseReleased(java.awt.event.MouseEvent e)
{
getCoordinate(e.getPoint());
if(MessageProcess.md_Move(chesson, pt.x, pt.y))
{
String temp;
if(chesson > 9)
temp = Passwords.MOVE+chesson+(8-pt.x)+(9-pt.y);
else
temp = Passwords.MOVE+"0"+chesson+(8-pt.x)+(9-pt.y);
MyConnection.sendMessage(temp);
}
chesson = 0;
}
public void mousePressed(java.awt.event.MouseEvent e)
{
getPreCoordinate(e.getPoint());
chesson = ChessBoard.moment[prept.x][prept.y];
if(chesson != 0)
{
System.out.println("catch a chess "+chesson);
//AvailablePlace theap = new AvailablePlace(chesson,ChessBoard.moment);
}
}
public void getPreCoordinate(java.awt.Point apt)
{
int x = -1, y = -1;
//int temp1 = ChessBoard.piclength/2; //25
int temp2 = ChessBoard.a; //50
int temp1 = temp2/2;
x = apt.x - ChessBoard.offset;
y = apt.y - ChessBoard.offset;
for(int i = 0; ; i++)
{
if(x > (temp2*i -temp1) & x < (temp2*i +temp1))
{
prept.x = i;
//System.out.println("get x = "+i);
break;
}
if(i == 9)
{
System.out.println("point is out of ChessBoard because x ="+x);
break;
}
}
for(int i = 0; i < 10; i++)
{
if(y > (temp2*i - temp1) & ( y < temp2*i + temp1))
{
prept.y = i;
//System.out.println("get y = "+i);
break;
}
if(i == 10)
{
System.out.println("point is out of ChessBoard because y ="+y);
break;
}
}
}//getPreCoordinate()
public void getCoordinate(java.awt.Point apt)
{
int x = -1, y = -1;
//int temp1 = ChessBoard.piclength/2+10; //25
int temp2 = ChessBoard.a; //50
int temp1 = temp2/2;
x = apt.x - ChessBoard.offset;
y = apt.y - ChessBoard.offset;
for(int i = 0; ; i++)
{
if(x > (temp2*i -temp1) & x < (temp2*i +temp1))
{
pt.x = i;
// System.out.println("get x = "+i);
break;
}
if(i == 9)
{
System.out.println("point is out of ChessBoard because x ="+x);
break;
}
}
for(int i = 0; i < 10; i++)
{
if(y > (temp2*i - temp1) & ( y < temp2*i + temp1))
{
pt.y = i;
//System.out.println("get y = "+i);
break;
}
if(i == 10)
{
System.out.println("point is out of ChessBoard because y ="+y);
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -