picturepanel.java

来自「一个贪吃蛇游戏」· Java 代码 · 共 48 行

JAVA
48
字号
/**
 * @(#)PicturePanel.java
 * @A panel with a picture.
 *
 * @Link Scholes
 * @version 1.00 2008/7/21
 */

package GUI;

//Java core packages
import java.awt.*;

//Java extension packages
import javax.swing.*;

public class PicturePanel extends JPanel
{
	private int width;
	private int height;
	private String picture;
	private ImageIcon icon;
	
	//construct a picture panel with specified width,height and picture
	public PicturePanel(int a,int b,String s)
	{
		width = a;
		height = b;
		picture = s;
		setPreferredSize(new Dimension(width,height));
		setVisible(true);
	}
	
	//set the picture of the picture panel
	public void setPicture(String s)
	{
		picture = s;
		repaint();
	}
	
	//draw the picture of the picture panel
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		icon = new ImageIcon(picture);
		g.drawImage(icon.getImage(),0,0,null);
	}
}	//end class PicturePanel

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?