![](/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.