gpt4 book ai didi

java - 如何修复小程序参数

转载 作者:行者123 更新时间:2023-12-02 08:07:25 24 4
gpt4 key购买 nike

只有当我移动“setBackground(color);”时,我的程序才能正常工作。到“init()”。如何修复它?我的任务是传入与 RGB 值相对应的三个整数,并使用适当的 Color 构造函数来设置背景颜色。

import java.applet.*;
import java.awt.*;

public class AnAppletSubclass2b extends Applet {
int r;
int g;
int b;
Color color;
public void init()
{

String parmStringRED = getParameter("red");
r = Integer.parseInt(parmStringRED);
String parmStringGREEN = getParameter("green");
g = Integer.parseInt(parmStringGREEN);
String parmStringBLUE = getParameter("blue");
b = Integer.parseInt(parmStringBLUE);
Color color = new Color (r,g,b);

System.out.println("The parameter are: red: " + parmStringRED + ", green: " + parmStringGREEN + ", blue: " + parmStringBLUE);


}

public void paint(Graphics g)
{
setBackground(color);
System.out.println("In paint: n = " + n);
n++;
}

int n;
}
<HTML>
<HEAD>
<TITLE> AnApplet With Parms </TITLE>
</HEAD>
<BODY>
<p>Here is the output of my Program:</p>
<APPLET CODE="AnAppletSubclass2b.class" WIDTH=150 HEIGHT=100>
<PARAM name="red" value="25" >
<PARAM name="green" value="250">
<PARAM name="blue" value="120">
</APPLET>
</BODY>
</HTML>

最佳答案

您有一个颜色变量定义为字段,另一个定义为局部变量。改变

Color color = new Color (r,g,b);

color = new Color (r,g,b);

关于java - 如何修复小程序参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7936063/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com