📄 tilecomponent.java
字号:
/*
* TileComponent2.java
*
* Created on March 4, 2002, 2:22 AM
*/
package netwar.mapper;
import netwar.game.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import netwar.utils.*;
/** Extends AWT Component to draw a tile image on itself. Also handles image loading.
* @author Kyle Kakligian
*/
public class TileComponent extends JButton implements ActionListener {
/** currently selected tile.
*/
public static TileComponent curr;
public HexTypeM hexType;
public String fileName;
public Color c;
public boolean pass;
public Image bmp;
/** Creates a new TileComponent
* @param filename Filename of the tile's picture
* @param color tile's mini map color
* @param passable tile's passablity.
*/
public TileComponent(String filename, Color color, boolean passable) {
hexType = new HexTypeM(filename, color, passable);
HexM.hexTypes.append(hexType);
fileName = filename;
c = color;
pass = passable;
bmp = LoadImage.LoadWaitForImage(filename);
HexM.hexTypes.append(this);
addActionListener(this);
}
public void actionPerformed(java.awt.event.ActionEvent evt) {
//curr.invalidate();
curr = this;
netwar.Mapper.rightPanel.updateUI(); // ugly hack
}
public Dimension getMinimumSize() {return getPreferredSize();} public java.awt.Dimension getMaximumSize() {return getPreferredSize();} public java.awt.Dimension getPreferredSize() {
return new Dimension(100, 100);
}
public void paint(java.awt.Graphics g) {
g.setColor(c);
g.fillRect(0,0,getWidth(),getHeight());
if(bmp != null) g.drawImage(bmp,0,0,getWidth(),getHeight(),this);
if(this == curr) {
g.setColor(Color.red);
g.drawRect(0,0,getWidth(),getHeight());
g.drawRect(1,1,getWidth()-2,getHeight()-2);
g.drawRect(2,2,getWidth()-4,getHeight()-4);
}
}
public void setBounds(int x, int y, int w, int h) {
if(w>getPreferredSize().width)
w = getPreferredSize().width;
if(h>getPreferredSize().height)
h = getPreferredSize().height;
super.setBounds(x,y,w,h);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -