2012-12-10 31 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:

相关问题