📄 map1.java
字号:
import java.awt.*;
class Map1 extends Map {
private int[] colorPoints = null;
int polx [] = new int [4];
int poly [] = new int [4];
private static final int lineWidth = 3;
private Color color = Color.blue;
public Map1 ( int xdiffini, int ydiffini ) {
xdiff = ydiffini;
ydiff = ydiffini;
}
public void paint ( Graphics f ) {
Dimension d = getSize();
f.setColor ( Color.white );
f.fill3DRect( 0, 0, d.width-1, d.height-1, true);
double s = World.scaling;
for ( int i = 0; i < kante_length; i++ ) {
f.setColor ( Color.black );
if (( colorPoints != null) && ( colorPoints[0] == i || colorPoints[1] == i)) {
f.setColor( color);
float dx = ( points[(i+1)%kante_length].x-points[i].x);
float dy = ( points[(i+1)%kante_length].y-points[i].y);
double alpha = ((dx != 0)?(float)Math.atan (dy/dx):Math.PI/2);
int diffx = - (int) Math.round( ( lineWidth/2) * Math.sin( alpha ));
int diffy = + (int) Math.round( ( lineWidth/2) * Math.cos( alpha ));
polx [0] = (int) Math.round( s*points[i].x) + diffx;
poly [0] = (int) Math.round( s*points[i].y) + diffy;
polx [1] = (int) Math.round( s*points[i].x) - diffx;
poly [1] = (int) Math.round( s*points[i].y) - diffy;
polx [2] = (int) Math.round( s*points[(i+1)%kante_length].x) - diffx;
poly [2] = (int) Math.round( s*points[(i+1)%kante_length].y) - diffy;
polx [3] = (int) Math.round( s*points[(i+1)%kante_length].x) + diffx;
poly [3] = (int) Math.round( s*points[(i+1)%kante_length].y) + diffy;
f.fillPolygon ( polx, poly, 4 );
} else {
f.drawLine ( (int)(s*points[i].x), (int)(s*points[i].y),
(int)(s*points[(i+1)%kante_length].x), (int)(s*points[(i+1)%kante_length].y) );
}
f.setColor ( Color.red );
if ( i == 0 ) {
f.fillRect ( (int)(s*(points[i].x)), (int)(s*(points[i].y)), (int)6, (int)6 );
} else f.fillRect ( (int)(s*(points[i].x)), (int)(s*(points[i].y)), (int)4, (int)4 );
}
}
public void setColorPoints( int[] p, Color c) {
this.color = c;
colorPoints = p;
repaint();
}
public void setColorPoints( Color c) {
this.color = c;
repaint();
}
public void unsetColorPoints( ) {
colorPoints = null;
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -