Eclipse没有打开框架窗口

时间:2013-12-10 07:19:45

标签: java eclipse jframe

我在Eclipse Indigo中运行了这个代码,没有框架作为输出打开,但是当我在BLUEJ中运行相同的代码时,它正常工作并且框架正在打开。 Plz告诉我这个错误。

这是我的代码:

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

public class MainFrame extends JFrame 
{

 void MainFrame()
{
    setTitle("Square's Root Finder");
    setSize(350,100);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLookAndFeel();
    setVisible(true);
    JButton but1 = new JButton("Calculate");
    JLabel label1= new JLabel("Enter the number:");
    JTextField t = new JTextField();
    add(but1);
    add(label1);
    add(t);


}
 private void setLookAndFeel() {
      try {
      UIManager.setLookAndFeel(
      "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
      } catch (Exception exc) {
      // ignore error
      }
      }

public static void main(String[] args)
{
    MainFrame newFrame = new MainFrame();

}

      }

1 个答案:

答案 0 :(得分:2)

Bug就在这一行:

 void MainFrame()

将其更改为:

public MainFrame()

根据JAVA documentation

,构造函数不应具有返回类型
  

构造函数声明看起来像方法声明 - 除了它们使用类的名称并且没有返回类型。

相关问题