我想从参数中传递一种颜色来更改文本的颜色,但是当我将param
元素放入 HTML 中时,根本没有显示颜色。我正在使用 Netbeans 7.1。
为什么不显示颜色?
HTML
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="ex1/ex11.class" width=350 height=200>
<PARAM name="color" value="black"/>
</APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>
代码
package ex1;
import java.awt.*;
import javax.swing.JApplet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class ex11 extends JApplet implements ActionListener{
int i ;
String color;
@Override
public void init()
{
Timer timer = new Timer(600, this);
timer.start();
i=0;
this.setSize(900,900);
}
@Override
public void paint(Graphics g)
{
g.clearRect(0, 0, this.getWidth(), this.getHeight());
g.setFont(new Font(Font.MONOSPACED, Font.BOLD, 40));
g.setColor(Color.getColor(getParameter("color")));
g.drawString(""+i, 250, 150);
}
public void actionPerformed(ActionEvent e)
{
if (i <5)
{
i= i+1;
repaint();
}
}
}