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

📄 htmlpage.java

📁 《湖泊生态的简单模拟》(Simulation Of Living Beings In A Lake )。这是我修读美国卡耐基梅隆大学Carnegie Mellon University(CMU)课程s
💻 JAVA
字号:
import java.io.*;
/**
 * Class that builds the HTML source for a HTML document.
 *
 * @author	张维
 * @version 1.0.0
 */
public class HtmlPage {
	private String pageTitle;
	private String pageBody;
	private String bgImage;
	private String bgColor;

	/**
	 *  Constructor
	 */
	HtmlPage() {
		pageTitle = "";
		pageBody = "";
		bgImage = "";
		bgColor = "";
	}

	/**
	 *  Build the page header
	 */
	private String getHeader() {
		return ("<HTML><HEAD><TITLE>" + pageTitle + "</TITLE></HEAD>");
	}

	/**
	 *  Build the page footer
	 */
	private String getFooter() {
		return ("</HTML>");
	}

	/**
	 *  Set the page title
	 */
	public void setTitle(String pTitle) {
		pageTitle = pTitle;
	}

	/**
	 *  Set the body background image attribute
	 */
	public void setBackgroundImage(String imageName) {
		bgImage = imageName;
	}

	/**
	 *  Set the body background color attribute
	 */
	public void setBackgroundColor(String colorValue) {
		bgColor = colorValue;
	}

	/**
	 *  Build the page body
	 */
	private String getBody() {

		return (
			"<BODY background='"
				+ bgImage
				+ "' bgcolor='"
				+ bgColor
				+ "'>"
				+ pageBody
				+ "</BODY>");
	}

	/**
	 *  Build the document type
	 */
	private String getDoctype() {

		return ("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>");
	}

	/**
	 *  Add a line of text to the body
	 */
	public void addText(String textString) {
		pageBody = pageBody + textString;
	}

	/**
	 *  Build the page now
	 */
	public String buildHtml() {

			String pageString = getDoctype() + // Add document type
					    getHeader() + // Add header
					    getBody() + // Add body
					    getFooter(); // Add footer

		return pageString;
	}
}

⌨️ 快捷键说明

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