2012-12-10 27 views
-1

我如何調用一個方法字符串(printBestillingsordre)到另一個方法,並創建一個JPanel它我如何調用一個字符串方法到一個JPanel

public String printBestillingsordre(){ 
     JButton button = new JButton("Varemodtaget"); 
     String temp = ""; 
     for(HentbestillingsordreRegistrer hentboregistrer: hbor){ 
     if(status == "Leveret"){  

     temp += "Bestillings Status: " + hentboregistrer.BestillingsStatus+" \n" + 
     "LeverandoerID: "+ hentboregistrer.LeverandoerID+" \n"; 


     }else{ 
      temp += hentboregistrer.BestillingsStatus+ button + "\n" + 
        "LeverandoerID: "+ hentboregistrer.LeverandoerID+" \n"; 
     } 
     System.out.println(temp); 

    } 
     return temp; 
} 

這個代碼

public JPanel HentOrdreGUI(){ 

    JPanel info = new JPanel(); 
    info.setLayout(new BorderLayout()); 
    info.add(printBestillingsordre()); 
    return null; 
} 

BTW這段代碼很長時間沒有完成

+0

1)'public JPanel HentOrdreGUI()'請學習常見的[Java命名約定](http://java.sun.com/docs/books/jls/ second_edition/html/names.doc.html#73307)(具體用於名稱的情況),用於類,方法和屬性名稱並一致使用它。 2)爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 3)具有教學意義的例子在用聽衆理解的語言時更具啓發性。請使用基於英文的標識符來表示屬性和方法。 –

+0

只是讓我明白你的問題。方法printBestillingsordre()返回一個你想要顯示在面板上的字符串?如果是這樣,那麼你需要創建一個JLabel來表示字符串。 – cworner1

+0

爲什麼你從'HentOrdreGUI()'返回null?你檢查了cworner1的答案嗎? –

回答

2

假設您想要將「printBestillingsordre()」的可視文本添加到Panel中,最簡單的方法是更改​​行:

info.add(printBestillingsordre()); 


info.add(new JLabel(printBestillingsordre()); 

這將創建的字符串的視覺代表。要組織你的GUI組件,我建議看看下面的link:

相關問題