?? gameimagepanel.java
字號:
/*
* Created on 2005-6-14
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package view;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;
/**
* @author rover
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class GameImagePanel extends JPanel {
GameImagePanel() {
super();
edge = 3;
}
public void setEdge(int edge) {
this.edge = edge;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (imageBoard == null)
return;
this.drawMapFrame(0, 0, getWidth(), getHeight(), edge, true, g);
this.drawMapFrame(x - edge, x - edge, imageWidth + edge * 2, y
- (x - edge) * 2, edge, false, g);
this.drawMapFrame(x - edge, y - edge, imageWidth + edge * 2,
imageHeight + edge * 2, edge, false, g);
g.drawImage(imageBoard, x, y, null);
}
public void setImageBoard(Image imageBoard) {
this.imageBoard = imageBoard;
this.imageWidth = imageBoard.getWidth(null);
this.imageHeight = imageBoard.getHeight(null);
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
//draw the map side frame
private void drawMapFrame(int x, int y, int width, int height, int side,
boolean raised, Graphics g) {
//the sets of coordinate of side Polygons
int setX[][] = { { x, x + width, x + width - side, x + side },//up
{ x + width - side, x + width, x + width, x + width - side },//right
{ x + side, x + width - side, x + width, x },//down
{ x, x + side, x + side, x } };//left
int setY[][] = {
{ y, y, y + side, y + side },//up
{ y + side, y, y + height, y + height - side },//right
{ y + height - side, y + height - side, y + height, y + height },//down
{ y, y + side, y + height - side, y + height } };//left
//draw the side polygons
for (int i = 0; i <= 3; i++) {
if (raised) {//raised
switch (i) {//set color
case 0:
g.setColor(new Color(244, 242, 232));
break;
case 1:
g.setColor(new Color(152, 150, 139));
break;
case 2:
g.setColor(new Color(102, 101, 93));
break;
case 3:
g.setColor(new Color(240, 238, 224));
break;
}
// switch (i) {//set color
// case 0:
// g.setColor(new Color(244, 242, 232));
// break;
// case 1:
// g.setColor(new Color(152, 150, 139));
// break;
// case 2:
// g.setColor(new Color(102, 101, 93));
// break;
// case 3:
// g.setColor(new Color(240, 238, 224));
// break;
// }
} else {//lowered
// switch (i) {//set color
// case 0:
// g.setColor(new Color(102, 101, 93));
// break;
// case 1:
// g.setColor(new Color(240, 238, 224));
// break;
// case 2:
// g.setColor(new Color(244, 242, 232));
// break;
// case 3:
// g.setColor(new Color(152, 150, 139));
// break;
// }
switch (i) {//set color
case 0:
g.setColor(new Color(100, 100, 100));
break;
case 1:
g.setColor(new Color(240, 240, 240));
break;
case 2:
g.setColor(new Color(250, 250, 250));
break;
case 3:
g.setColor(new Color(120, 120, 120));
break;
}
}
g.fillPolygon(setX[i], setY[i], 4);//draw
}
}
private int edge;
private int imageHeight;
private int imageWidth;
private Image imageBoard;
private int x;
private int y;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -