需要找出我的代码出错

问题描述:

一直工作在Java中,这GUI代码,我不断收到一个错误是:需要找出我的代码出错

guiconstruct.java:30: error: invalid method declaration; return type required ÏϧÏpublic Evaluate_7();

我希望有人能告诉我这是什么错误表示。我知道它的公开评估结果接近尾声,那是我至少相信的。非常感激任何的帮助。

谢谢。下面的代码:

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.text.DecimalFormat; 

public class guiconstruct extends JFrame { 

    private JLabel blankoneL, blanktwoL, blankthreeL, 
      scoreL, weightL, oneL, twoL, threeL, fourL, averageL; 

    private JTextField oneTF, twoTF, threeTF, fourTF, woneTF, wtwoTF, 
      wthreeTF, wfourTF, averageTF; 

    private JButton submitB, resetB, exitB; 

    private SubmitButtonHandler sbHandler; 
    private ResetButtonHandler rbHandler; 
    private ExitButtonHandler ebHandler; 
    //indicate the size of the window 

    private static final int WIDTH = 500; 

    private static final int HEIGHT = 400; 

    public Evaluate_7(); 
    { 
     //Create labels 
     blankoneL = new JLabel(""); 
     blanktwoL = new JLabel(""); 
     blankthreeL = new JLabel(""); 

     scoreL = new JLabel("Score", SwingConstants.CENTER);//swingConstants." " tells the program how to align the text in the window 
     weightL = new JLabel("Weight", SwingConstants.CENTER); 
     oneL = new JLabel("Test Score One: ", SwingConstants.RIGHT); 
     twoL = new JLabel("Test Score Two: ", SwingConstants.RIGHT); 
     threeL = new JLabel("Test Score Three: ", SwingConstants.RIGHT); 
     fourL = new JLabel("Test Score Four: ", SwingConstants.RIGHT); 
     averageL = new JLabel("Weighted Average: ", SwingConstants.RIGHT); 

     //Create textfields 
     oneTF = new JTextField(5); 
     twoTF = new JTextField(5); 
     threeTF = new JTextField(5); 
     fourTF = new JTextField(5); 
     woneTF = new JTextField(5); 
     wtwoTF = new JTextField(5); 
     wthreeTF = new JTextField(5); 
     wfourTF = new JTextField(5); 
     averageTF = new JTextField(5); 

     //create Submit Button 
     submitB = new JButton("Submit"); 
     sbHandler = new SubmitButtonHandler(); 
     submitB.addActionListener(sbHandler); 
     //Create Reset Button 
     resetB = new JButton("Reset"); 
     rbHandler = new ResetButtonHandler(); 
     resetB.addActionListener(rbHandler); 

     //Create Exit Button 
     exitB = new JButton("Exit"); 
     ebHandler = new ExitButtonHandler(); 
     exitB.addActionListener(ebHandler); 

     //Set the title of the window 
     setTitle("Evaluate 6 IT145"); 

     //Get the container 
     Container pane = getContentPane(); 

     //Set the layout 
     pane.setLayout(new GridLayout(7, 3)); 

     //Place the components in the pane 
     pane.add(blankoneL); 
     pane.add(scoreL); 
     pane.add(weightL); 
     pane.add(oneL); 
     pane.add(oneTF); 
     pane.add(woneTF); 
     pane.add(twoL); 
     pane.add(twoTF); 
     pane.add(wtwoTF); 
     pane.add(threeL); 
     pane.add(threeTF); 
     pane.add(wthreeTF); 
     pane.add(fourL); 
     pane.add(fourTF); 
     pane.add(wfourTF); 
     pane.add(averageL); 
     pane.add(averageTF); 
     pane.add(blanktwoL); 
     pane.add(submitB); 
     pane.add(resetB); 
     pane.add(exitB); 
     //set the size of the window and display it 

     setSize(WIDTH, HEIGHT); 
     setVisible(true); 
     setDefaultCloseOperation(EXIT_ON_CLOSE); 
    } 

    private class SubmitButtonHandler implements ActionListener { 

     public void actionPerformed(ActionEvent e); 

     private class ResetButtonHandler implements ActionListener { 

      public void actionPerformed(ActionEvent e); 
      { 
       double one, wone, two, wtwo, three, wthree, four, wfour, ave; 

       twoDigits = new DecimalFormat("0.00"); 
       one = Double.parseDouble(oneTF.getText()); 
       wone = Double.parseDouble(woneTF.getText()); 
       two = Double.parseDouble(twoTF.getText()); 
       wtwo = Double.parseDouble(wtwoTF.getText()); 
       = Double.parseDouble(threeTF.getText()); 

       wthree = Double.parseDouble(wthreeTF.getText()); 
       four = Double.parseDouble(fourTF.getText()); 
       wfour = Double.parseDouble(wfourTF.getText()); 
       ave = (one * wone + two * wtwo + three * wthree + four * wfour)/(wone + wtwo + wthree + wfour); 

       averageTF.setText("" + twoDigits.format(ave)); 
      } 
     } 

     private class ExitButtonHandler implements ActionListener { 

      public void actionPerformed(ActionEvent e); 
      { 
       System.exit(0); 
      } 
     } 

     public static void main(String[] args) { 
      Evaluate_7 wAveObject = new Evaluate_7(); 
     } 
    } 
} 
+2

代码可能受益于缩进 – Coffee 2014-12-03 20:57:09

+0

如错误消息所述,需要返回类型。当你创建一个方法时,你需要指定该方法返回的“类型”。如果该方法返回什么,它被认为是一个'void',所以你应该声明它喜欢: '公共无效Evaluate_7(){这里 代码 }' – Scott 2014-12-03 20:58:49

+2

这就像在如何不上问一个问题的案例研究互联网。 – 2014-12-03 21:05:43

你命名你的guiconstruct类,但那么你命名的构造Evaluate_7(并有上线的最后一个分号)。所以编译器认为Evaluate_7是一种方法,它确实会遗漏返回类型。