⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picturetextpanel.java

📁 一个贪吃蛇游戏
💻 JAVA
字号:
/**
 * @(#)PictureTextPanel.java
 * @A panel with picture and text.
 *
 * @Link Scholes
 * @version 1.00 2008/7/21
 */

package GUI;

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

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

public class PictureTextPanel extends JPanel
{
	private int width;
	private int height;
	private String picture;
	private String text;
	private ImageIcon icon;
	
	//construct a picture text panel with specified width,height,picture and text
	public PictureTextPanel(int a,int b,String s,String t)
	{
		width = a;
		height = b;
		picture = s;
		text = t;
		setPreferredSize(new Dimension(width,height));
		setVisible(true);
	}
	
	//set the picture of the picture text panel
	public void setPicture(String s)
	{
		picture = s;
		repaint();
	}
	
	//draw the picture and text of the picture text panel
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		icon = new ImageIcon(picture);
		g.drawImage(icon.getImage(),0,0,null);
		g.setColor(Color.white);
		g.setFont(new Font("Monospaced",Font.BOLD,32));
		g.drawString(text,16,height - 4);
	}
}	//end class PictureTextPanel

⌨️ 快捷键说明

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