2017-09-29 51 views
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)); 
       } 
      } 
    } 

我真的不確定在哪裏需要放置括號。請有人能幫助這將是很棒的!

+0

你缺少該類的右大括號。使用一個編輯器(Eclipse,Netbeans和其他許多其他的)會給你錯誤。 – Pratham

+0

你使用哪個代碼編輯器? –

回答

0
  1. 而不是使用

    Integer.toString(...) 
    

    使用

    String.valueOf(...) 
    
  2. 您不能引用靜態類非靜態類。使FahrenheitPanel類爲靜態。發佈的代碼在最後缺少括號。