2015-05-09 89 views
0
public void buildButtonPanel() 
    { 

    buttonPanel = new JPanel(); 

    calcButton = new JButton("Calculate Charges"); 
    exitButton = new JButton("Exit"); 


    calcButton.addActionListener(new CalcButtonListener()); 
    exitButton.addActionListener(new ExitButtonListener()); 


    buttonPanel.add(calcButton); 
    buttonPanel.add(exitButton); 



     private class CalcButtonListener implements ActionListener 
     { 

      public void actionPerformed(ActionEvent e) 


       total = routine.getRoutineCost() + 
         nonRoutine.getNonRoutineCost(); 

       DecimalFormat dollar = new DecimalFormat("0.00"); 

       JOptionPane.showMessageDialog(null, "Total: $" + dollar.format(total)); 

     } 

     private class ExitButtonListener implements ActionListener 
     {    

      public void actionPerformed(ActionEvent e) 


       System.exit(0); 
     } 

錯誤時預期:類,接口,或枚舉預期錯誤:類,接口,或枚舉編譯

在每行同樣的錯誤。

我假設它是一個大括號的錯誤,但我已經重做了我的大括號3次,而且我仍然在同一部分發生同樣的錯誤。

+1

在整個buildButtonPanel類的末尾沒有閉合大括號。錯誤出現在哪裏? –

+0

它從public void buildButtonPanel開始。如果有幫助,錯誤的指標在第一行的void下,然後繼續在calcButton = new JButton(「Calculate Charges」); – LizzySmit

+0

包含此類的文件中是否還有其他內容?這個問題可能來自課堂上的某些事情。你有沒有看到我說過在課程結束時你沒有右括號? –

回答

1

buildButtonPanel需要在類之前有一個右大括號。

它需要去這裏,因爲你不能在方法內部有類。

buttonPanel.add(exitButton); 
} 

你給我們展示的所有代碼都包裝在一個類中嗎? buildButtonPanel是一種方法,必須在一個類中。

你的actionPerformed方法也沒有大括號。

public void actionPerformed(ActionEvent e) { 
    // Your code goes here 
}