place.java
来自「petrinets小程序」· Java 代码 · 共 133 行
JAVA
133 行
import java.awt.Color;
import java.awt.Point;
public class place implements Cloneable {
private static final int radius = 15;
private String name;
private int tokens;
private int x, y;
private int xName, yName;
private Color color;
public place(){
name = "";
tokens = 0;
x = 0;
y = 0;
xName = 0;
yName = 0;
color = Color.BLACK;
}
public place(String string){
name = string;
tokens = 0;
x = 0;
y = 0;
xName = 0;
yName = 0;
color = Color.BLACK;
}
public static int getRadius(){
return radius;
}
public void setX( int x ){
this.x = x;
}
public int getX(){
return x;
}
public void setY( int y ){
this.y = y;
}
public int getY(){
return y;
}
public void setXName( int xName ){
this.xName = xName;
}
public int getXName(){
return xName;
}
public void setYName( int yName ){
this.yName = yName;
}
public int getYName(){
return yName;
}
public Point getNamePosition(){
return new Point( xName, yName );
}
public void setColor( Color color ){
this.color = color;
}
public Color getColor(){
return color;
}
public void setName( String name ){
this.name = name;
}
public String getName(){
return name;
}
public void setTokens( int tokens ){
this.tokens = tokens;
}
public int getTokens(){
return tokens;
}
public void decTokens( int weight ){
if( tokens >= weight )
tokens -= weight;
}
public void decTokens(){
if( tokens >=1 )
tokens--;
}
public void incTokens( int weight ){
tokens += weight;
}
public void incTokens(){
tokens++;
}
public boolean isTokensSuperWeight( int weight ){
if( tokens >= weight )
return true;
else
return false;
}
public double distanceToOnePoint( double x, double y ){
double dx = ( this.x - x );
double dy = ( this.y - y );
return Math.sqrt( dx*dx + dy*dy );
}
public synchronized Object clone() {
place n = new place();
n.setName( name );
n.setTokens( tokens );
n.setColor( color );
n.setX( x );
n.setY( y );
n.setXName( xName );
n.setYName( yName );
return n;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?