在我的 for 循环中,它似乎忽略了 if 语句
我对java很陌生,我一直在尝试编写一种方法来绘制从一种可配置颜色到另一种可配置颜色的渐变。但是,for 循环内的 if 语句似乎被忽略。
我该如何解决这个问题?还是我还缺少其他东西?
该方法的用法是:
Gradient.dVertical(Graphics,左上角X,左上角Y,尺寸X,尺寸Y,起始红色值,起始绿色值,起始蓝色值,结束红色值,结束绿色值,结束蓝色值);
编辑:我找出了真正的问题是什么并解决了它。当它应该逐渐下降时,它却上升了。所以我又添加了几个 if 语句,结果就解决了。 在调用该方法时使用随机整数确实揭示了另一个问题。使用某些值,它不会完成绘制,只会在中间被切断。 FIXED
如果有人感兴趣,这里是代码的固定部分
if (rrepeat == true)
{
//prevents division by zero
if(rrate!=0)
{
//for a rate that must repeat checks
//whether or not it is time to increment
check = k%rrate;
if (check==0)
{
if(ered<sred)
{
rr--;
}
if(sred<ered)
{
rr++;
}
}
else
{
rr = rr;
}
}
}
I'm pretty new at java and I've been trying to write a method that draws a gradient from one configurable color to another. However, it appears that if statements inside of the for loop are being ignored.
How can I fix this? or is there something else I'm missing?
and usage of the method is:
Gradient.dVertical(Graphics,Top left corner X,Top left corner Y,Size X,Size Y,tarting Red Value,Starting Green Value,Starting Blue Value,Ending Red Value,Ending Green Value,Ending Blue Value);
EDIT: I figured out what the real problem was and I fixed it. When it should have been incremental down it was going up. So I added a couple more if statements and that cleared it up.Using random integers when calling the method did reveal another problem though. With certain values it will not finish drawing and it will just cut off in the middle. FIXED
Here's the fixed part of the code if anyone is interested
if (rrepeat == true)
{
//prevents division by zero
if(rrate!=0)
{
//for a rate that must repeat checks
//whether or not it is time to increment
check = k%rrate;
if (check==0)
{
if(ered<sred)
{
rr--;
}
if(sred<ered)
{
rr++;
}
}
else
{
rr = rr;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要重写
paint
方法。下面是一个示例:小程序简介
You need to be overriding the
paint
method.Here's an example: Introduction to applets