Parsinng

时间:2017-09-29 06:43:04

标签: parsing

我遇到一个错误,说我在解析时已经到达了文件的末尾。我知道该怎么做,但我不确定丢失的支架应该去哪里。请帮助!

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));
              }
            }
    }

我真的不确定我需要放置支架的位置。如果有人能提供帮助那就太棒了!

1 个答案:

答案 0 :(得分:0)

  1. 改为使用

    Integer.toString(...)
    

    使用

    String.valueOf(...)
    
  2. 您不能在静态类中引用非静态类。使FahrenheitPanel类静态。并且发布的代码在最后没有括号。