所以我现在教自己的GUI编码与大学的Java书,我明白这一切,但我ge这个错误,我很难过。非静态变量这不能从静态内容中引用Java
import javax.swing.*;
import BreezySwing.*;
public class gui
{
public class ConvertWithGUI extends GBFrame
{
private JLabel fahrenheitLabel;
private JLabel celsiusLabel;
private DoubleField fahrenheitField;
private DoubleField celsiusField;
private JButton fahrenheitButton;
private JButton celsiusButton;
public ConvertWithGUI()
{
fahrenheitLabel = addLabel ("Fahrenheit" ,1,1,1,1);
celsiusLabel = addLabel ("Celsius" ,1,2,1,1);
fahrenheitField = addDoubleField (32.0 ,2,1,1,1);
celsiusField = addDoubleField (0.0 ,2,2,1,1);
fahrenheitButton= addButton (">>>>>>" ,3,1,1,1);
celsiusButton = addButton ("<<<<<<" ,3,2,1,1);
}
public void buttonClicked (JButton buttonObj)
{
Thermometer thermo = new Thermometer();
if (buttonObj == fahrenheitButton)
{
thermo.setFahrenheit(fahrenheitField.getNumber());
celsiusField.setNumber (thermo.getCelsius());
}
else
{
thermo.setCelsius(celsiusField.getNumber());
fahrenheitField.setNumber (thermo.getFahrenheit());
}
}
public static void main(String[] args)
{
ConvertWithGUI theGUI = new ConvertWithGUI();
theGUI.setSize(250, 100);
theGUI.setVisible(true);
}
}
}
确定,所以一切都交给了一部分标记为:
ConvertWithGUI theGUI = new ConvertWithGUI();
导致错误。更具体地说,它是强调在这一部分:
new ConvertWithGUI();
现在这个程序的基本功能是从和摄氏度转换。我知道这很简单,但我不知道这个错误是什么,而且我正在从书中输入。 如果有人可以帮助它,将不胜感激!谢谢。
谢谢!愚蠢的小错误,我忽视了。再次感谢! –