dynamichtml.java

来自「用java编写的动态网页效果」· Java 代码 · 共 52 行

JAVA
52
字号
// DynamicHTML.java -- Written by Chuck Wood for Visual J++ Secrets
import wfc.html.*;
// Step 1: Make a new class that inherits DhModule
public class DynamicHTML extends DhModule {
// Step 2: override the loader method
	public void documentLoad(Object sender, DhEvent p) {
	//Step 3: Create any elements
		DhButton button1 = new DhButton();
		DhButton button2 = new DhButton("Button 2");
		DhText text1 = new DhText("DynamicHTML");
	// Step 4: get the containing document
		DhDocument doc = getDocument();
	// Step 5: Add elements to the document
		button1.setText("Button 1");
		DhStyle s = new DhStyle();
		s. setColor(DhColors.DARKMAGENTA);
		s.setFont( "arial", 14 );
		text1.setStyle(s);
		doc.add(text1);		// Add a text
		doc.newLine();		// Go to the next line
		doc.newLine();		// Go to the next line
		doc.add(button1);	// Add a button
		doc.add(button2);	// Add a button
	// Step 6: Add any event handlers to the elements
		button1.addOnClick(new DhEventHandler(button1Click));
		button2.addOnClick(new DhEventHandler(button2Click));
	}
	// Step 7: Code the event handler
//button1Click is called whenever the button2 is clicked
	public void button1Click( Object sender, DhEvent e) {
	// Get the containing document
		DhDocument doc = getDocument();
	// Make a new text element
		DhText t = new DhText("Button 1 was clicked");
	// Add a new line to the containing document
		doc.newLine();
	// Add the text to the document
		doc.add(t);
	}
//button2Click is called whenever the button2 is clicked
	public void button2Click( Object sender, DhEvent e) {
	// Get the containing document
		DhDocument doc = getDocument();
	// Make a new text element
		DhText t = new DhText("Button 2 was clicked");
	// Add a new line to the containing document
		doc.newLine();
	// Add the text to the document
		doc.add(t);
	}
}

⌨️ 快捷键说明

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