2012-07-13 78 views

回答

6

的構造函數的名稱必須是相同的類名,所以改變任何改變類名labelFrame或構造函數名稱labelsAndIcons

(平時注意第一個字母是Java中的大寫字母)

public class LabelFrame extends JFrame { 
    public LabelFrame() { 
     super("Testing JLabel"); 
    } 
} 
2

你的意思

public class labelsAndIcons extends JFrame { 
    public labelsAndIcons() 
    { 
     super("Testing JLabel"); 
    } 
} 
0

的構造函數的名稱必須是相同的類名。 讓我們來看看這個:

constructor call must be the first statement in a constructor 

constructor call引用父類的構造函數的構造函數字這是​​

in a constructor構造詞指的是你的類的consucor即:public labelsAndIcons()

所以您需要將您的代碼縮小至此:

public class labelsAndIcons extends JFrame 
{ 
    public labelsAndIcons() 
    { 
    super("Testing JLabel"); 
    } 
} 
0

理想的情況下你的代碼應該失敗說Invalid Method declartion因爲public labelFrame()

  • 既不是一個構造函數(因爲構造函數具有相同的名稱作爲類名)
  • 既不是正確的方法聲明。

無論改變這樣的代碼:

public class labelsAndIcons extends JFrame 
{ 
    public labelsAndIcons() 
    { 
    super("Testing JLabel"); 
    } 
} 
相關問題