![](/img/trans.png)
[英]Why isn't -XX:+ExplicitGCInvokesConcurrent the default when using the G1 collector?
[英]JPanel.setBounds(xx,xx,variable,xx) isn't working. why?
public void colortemperatureJSliderStateChanged(ChangeEvent event) {
fahrenheitdegree = colortemperatureJSlider.getValue();
fahrenheitJPanel.setBounds(100,270, fahrenheitdegree, 20);
celsiusdegree = (fahrenheitdegree - 32.0)*5.0/9.0;
celsiusJPanel.setBounds(100,220,celsiusdegree, 20);
}// end of public void colortemperatureJSliderStateChanged..
我的教授希望将两个变量(摄氏温度和华氏温度)都设置为双精度,因此我将摄氏度设置为双精度。 华氏度;
不知何故,编译在JPanel.setBounds(xxx,xxx,variable,xx)的两行上识别出两个错误; 因为它是“不兼容的类型:可能从双精度转换为整数”。
当我尝试将变量更改为int时。 错误是摄氏温度的公式无法识别int。 那么如何使它适用于双变量?
为了使此功能成倍增加,您应该将变量保留为double并告诉编译器无论如何都要执行有损对话。
所以:
celsiusJPanel.setBounds(100, 220, (int) celsiusdegree, 20);
应该工作正常。
有关更多信息,请参见“为什么int / byte / short / long可以在不进行类型转换的情况下转换为float / double,但反之亦然” ,以及JLS的相关部分
JPanel的setBounds将面板的右上角设置为第一个和第二个参数,作为x,y坐标。 第三个和第四个参数分别指定宽度和高度。 您将需要创建标签或文本字段以显示您的值。
我建议将celsiusdegree
和fahrenheitdegree
保留为Double
,然后将setBounds用作以下内容:
celsiusJPanel.setBounds(100, 220, celsiusdegree.intValue(), 20);
因为您不能将Double转换为int 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.