applet example

最近想在浏览器里面写个坐标系统,用java applet。
public class AppletTest1 extends Applet {
	StringBuffer buffer;
	String word;
	public void init(){
		buffer=new StringBuffer();
		addItem("initializing...");
	}
	public void start(){
		addItem("starting...");
		setSize(500,500);
	}
	public void stop(){
		addItem("stopping...");
	}
	public void destroy(){
		addItem("preparing for destroy...");
	}
	void addItem(String newWord){
		System.out.println(newWord);
		buffer.append(newWord);
		repaint();
	}
	public void paint(Graphics g){
		
		/*g.drawRect(0,0,getSize().width-1,getSize().height-1);
		g.drawString(buffer.toString(),5,15);*/
	
		Graphics2D g2 =(Graphics2D)g;
		Shape shape = new Rectangle2D.Double(5,5,100,100);
		Color color = Color.GREEN;
		g2.setPaint(color);
		g2.fill(shape);
		g2.draw(shape);
		String para = getParameter("word");
		g2.drawString(para,200,15);
	}
	
}


注意的是传参数是通过getParameter("word");来实现的。
html代码应该为

<html>
<applet code=AppletTest1.class width=300 height=300>
	<param name=word value=models/HyaluronicAcid.xyz>
</applet>
</html>

你可能感兴趣的:(example)