📄 imageframe.java
字号:
import java.awt.*;
import Tile;
public class ImageFrame extends Frame {
static final int RED = 1, COMP = 2, ENTIRE_RED = 3, ENTIRE_COMP = 4;
static final Color color1 = Color.red, color2 = Color.black;
Image image;
Tile tile;
int halfSymbolSize = 8;
int type, index;
/*
typ is the type,
indx is the index of the composite tile, only if type is COMP
*/
public ImageFrame(Tile til, int typ, int indx) {
super(til.tileName);
tile = til;
type = typ;
index = indx;
switch (type) {
case RED: image = tile.redImage; break;
case ENTIRE_RED: image = Tile.redMap; break;
case COMP:
image = tile.compositeImages[ index ];
/* get the tileName from UpperLeftCorner / 256 */
setTitle(til.tileName + "-" + index + ": Comp Tile " +
tile.compCorners[ index ].y / 256 + "." +
tile.compCorners[ index ].x / 256);
break;
case ENTIRE_COMP: image = Tile.compMap; break;
default:
}
/* wait till image is loaded */
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image, 1);
try tracker.waitForID(1); catch (InterruptedException e);
if (tracker.isErrorID(1)) {
System.out.println("Error loading image ");
this.dispose();
}
else {
resize(image.getWidth(this), image.getHeight(this));
System.out.println(image.getWidth(this) + " "+ image.getHeight(this));
show();
}
}
public boolean handleEvent(Event evt) {
if (evt.id == Event.MOUSE_DOWN)
System.out.println("Point " + evt.x + ", " + evt.y);
if (evt.id == Event.KEY_PRESS || evt.id == Event.WINDOW_DESTROY) {
hide();
dispose();
}
return super.handleEvent(evt);
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
switch (type) {
case RED:
g.setColor(color1);
Point[] points = tile.getRedPoints();
for (int i = 0; i < points.length; i ++)
g.drawRect(points[ i ].x - halfSymbolSize, points[ i ].y -
halfSymbolSize,2 * halfSymbolSize, 2 * halfSymbolSize);
break;
case COMP:
g.setColor(color2);
int x = tile.compOffsets[ index ].x;
int y = tile.compOffsets[ index ].y;
g.drawRect(x - halfSymbolSize, y - halfSymbolSize,
2 * halfSymbolSize, 2 * halfSymbolSize);
/* draw two smaller ones to make rectangle look thicker */
g.drawRect(x - halfSymbolSize + 1, y - halfSymbolSize + 1,
2 * halfSymbolSize - 2, 2 * halfSymbolSize - 2);
g.drawRect(x - halfSymbolSize + 2, y - halfSymbolSize + 2,
2 * halfSymbolSize - 4, 2 * halfSymbolSize - 4);
break;
case ENTIRE_RED:
g.setColor(color1);
/*
Each red tile is 512x512,there are 17x24 such tiles in the entire map.
And the size of the tile is 26x26, so the scale is 20
*/
g.drawRect(tile.upperLeftCorner.x / 20,
tile.upperLeftCorner.y / 20, 26, 26);
break;
case ENTIRE_COMP:
g.setColor(color2);
/*
Composite tile is 256x256, there are 19x29 such tiles in the entire map.
And the size of the tile is 26x26, so the scale is 10
*/
for (int i = 0; i < tile.compositeNum; i++) {
g.drawRect(tile.compCorners[ i ].x / 10,
tile.compCorners[ i ].y / 10, 25, 25);
}
break;
default:
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -