java - 如何将作为参数从 html 文件传递到 java applet 程序中的矩形的颜色设置
问题描述
一个 java 小程序,用于显示具有指定坐标和颜色的矩形,作为 HTML 文件中的参数传递。我可以检索并设置从 html 文件作为参数传递的矩形的坐标,但我无法设置从 html 文件作为参数传递的颜色,如何做到这一点?我试过这段代码,但它不能正常工作。
import java.awt.*;
import java.applet.*;
/* <applet code="ParaRect" width=1200 height=1000>
<param name=x value=100>
<param name=y value=200>
<param name=color value="red">
</applet> */
public class ParaRect extends Applet{
public void paint(Graphics g){
String x=getParameter("color");
g.setColor(Color.x);
g.fillRect(Integer.parseInt(getParameter("x")),Integer.parseInt(getParameter("y")),150,100);
}
}
解决方案
'''
import java.awt.*;
import java.applet.*;
/* <applet code="ParaRect" width=1200 height=1000>
<param name=x value=100>
<param name=y value=200>
<param name="color" value="FF0000">
</applet> */
public class ParaRect extends Applet{
public void paint(Graphics g) {
Color col = new
Color(Integer.parseInt(this.getParameter("color"),16));
g.setColor(col);
g.fillRect(Integer.parseInt(getParameter("x")),Integer.parseInt(getParameter("y")),150,100); }
} '''
推荐阅读
- materialize - 物化选择不在模态中显示
- ruby-on-rails - 为什么我的 Rails URL 路由使用点而不是斜线呈现 URL?
- angularjs - 添加打字稿方法的签名
- android - 如何在 Android 的弹出窗口上处理点击侧的监听器?
- swift - 在 swift 中假设集合类型时类型推断的工作原理
- java - 将 Katalon Studio 更新到版本 5.9.1 - ClassNotFoundException
- c - 如何模拟 send() 以便对函数 commSendPacket 进行单元测试?
- python - 包含轮廓的图像中出现白点
- angular - 在角度 6 中使用 HttpResponse 时如何每 5 分钟调用一次 API
- azure - spark.conf.set 与 SparkR