textpanel.java

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

JAVA
60
字号
/**
 * @(#)TextPanel.java
 * @A panel with 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 TextPanel extends JPanel
{
	private int width;
	private int height;
	private int pound;
	private String text;
	private Color color;
	
	//construct a text panel with specified width,height,pound of the text and text
	public TextPanel(int a,int b,int c,String s)
	{
		width = a;
		height = b;
		pound = c;
		text = s;
		color = Color.white;
		setBackground(Color.black);
		setPreferredSize(new Dimension(width,height));
		setVisible(true);
	}
	
	//set the color of the text
	public void setColor(Color c)
	{
		color = c;
		repaint();
	}
	
	//set the text of the text panel
	public void setText(String s)
	{
		text = s;
		repaint();
	}
	
	//draw the text of the text panel
	protected void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		g.setColor(color);
		g.setFont(new Font("Monospaced",Font.BOLD,pound));
		g.drawString(text,0,height - pound);
	}
}	//end class TextPanel

⌨️ 快捷键说明

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