0
我遇到一个错误,说我已经到了文件的末尾,而解析。我有一个想法,应该怎么做,但我不确定哪些缺失的支架应该去。请帮忙!达到了代码结束虽然Parsinng
package fahrenheit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Fahrenheit {
public static void main(String[] args) {
JFrame frame = new JFrame ("Fahrenheit to Celsius");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
FahrenheitPanel panel = new FahrenheitPanel();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
public class FahrenheitPanel extends JPanel {
private JLabel inputLabel, outputLabel, resultLabel;
private JTextField fahrenheit;
public FahrenheitPanel() {
inputLabel = new JLabel ("Enter Fahrenheit Temperature:");
outputLabel = new JLabel ("Temperature in Celsius");
resultLabel = new JLabel ("---");
fahrenheit = new JTextField (5);
fahrenheit.addActionListener (new TempListener());
add (inputLabel);
add (fahrenheit);
add (outputLabel);
add (resultLabel);
setPreferredSize (new Dimension (300, 75));
setBackground (Color.yellow);
}
private class TempListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
int fahrenheitTemp, celsiusTemp;
String text = fahrenheit.getText();
fahrenheitTemp = Integer.parseInt (text);
celsiusTemp = (fahrenheitTemp-32) * 5/9;
resultLabel.setText (Integer.toString (celsiusTemp));
}
}
}
我真的不确定在哪里需要放置括号。请有人能帮助这将是很棒的!
你缺少该类的右大括号。使用一个编辑器(Eclipse,Netbeans和其他许多其他的)会给你错误。 – Pratham
你使用哪个代码编辑器? –