我很擅长使用JFrame和其他组件,例如JTextField,JLabel。我试图创建一个小程序,用户输入华氏温度并将其转换为摄氏温度。这是我到目前为止的代码
TempConverter.java
public static void main(String[] args){
JFrame frame = new JFrame("Temperature Converter");
Temperature temp = new Temperature();
JLabel temperature_label;
JTextField farenheit_temperature;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(400,400));
frame.setMaximumSize(new Dimension(400,400));
frame.setMinimumSize(new Dimension(400,400));
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setLayout(new FlowLayout());
temperature_label = new JLabel("Farenheit Converter");
temperature_label.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 18));
frame.add(temperature_label);
farenheit_temperature = new JTextField("Enter Farenheit Temperature", 50);
frame.add(farenheit_temperature);
frame.setVisible(true);
}
我不知道我在代码中做错了什么。一些帮助和解释我做错了什么将不胜感激。谢谢。
答案 0 :(得分:0)
public static void main(String[] args){
JFrame frame = new JFrame("Temperature Converter");
Temperature temp = new Temperature();
JLabel temperature_label;
JTextField farenheit_temperature;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setLayout(new FlowLayout());
temperature_label = new JLabel("Farenheit Converter");
temperature_label.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 18));
frame.getContentPane().add(temperature_label);
farenheit_temperature = new JTextField("Enter Farenheit Temperature", 30);
frame.getContentPane().add(farenheit_temperature);
frame.setVisible(true);
}