mappanel.java
来自「一个贪吃蛇游戏」· Java 代码 · 共 50 行
JAVA
50 行
/**
* @(#)MapPanel.java
* @A panel used to draw map.
*
* @Link Scholes
* @version 1.00 2008/7/21
*/
package GUI;
//Java core packages
import java.awt.*;
//Java extension packages
import javax.swing.*;
public class MapPanel extends JPanel
{
private int type;
private ImageIcon icon;
//construct a map panel with specified type
public MapPanel(int n)
{
type = n;
setPreferredSize(new Dimension(32,32));
setVisible(true);
}
//get the type of the map panel
public int getType()
{
return type;
}
//set the map panel with the specified type
public void setType(int n)
{
type = n;
repaint();
}
//draw the picture representing the type of the map panel
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
icon = new ImageIcon("img\\" + type + ".jpg");
g.drawImage(icon.getImage(),0,0,null);
}
} //end class MapPanel
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?