2013-12-10 44 views
0

我在Eclipse Indigo中運行了此代碼,並且沒有框架作爲輸出打開,但是當我在BLUEJ中運行相同的代碼時,它正常工作並且框架打開。 Plz告訴我這個錯誤。Eclipse未打開框架窗口

這裏是我的代碼:

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

} 

     } 

回答

2

錯誤是在這一行:

void MainFrame() 

將其更改爲:

public MainFrame() 

Constuctors不應該有返回類型爲每JAVA documentation

構造函數聲明看起來像方法聲明 - 除了它們使用類的名稱並且沒有返回類型。