2013-11-26 50 views
-1

如果有人能夠在這裏指出我正確的方向,那麼我對Java很陌生,陣列內的數組列表java

我試圖把不同的arraylist放入一個數組,所以我可以把這些數組對象放入Jlist。

我到目前爲止,但現在只是不能似乎填充我的Jlist與我想要的。

任何指針都會很棒。

private void btnCheckActionPerformed(java.awt.event.ActionEvent evt) {           

carmakes[] makes = new carmakes[3]; 
Audi [0] = new carmakes (AudiFeatures); 
BMW [1] = new carmakes (BMWFeatures); 

     DefaultListModel myModel = new DefaultListModel(); 
     myModel.addElement(makes); 
     lbxCarMake.setModel(myModel); 

// Create Car 
    ArrayList<String> AudiFeatures = new ArrayList<String>(); 
     AudiFeatures.add("Leather Seats"); 
     AudiFeatures.add("Bose Sound System"); 
     AudiFeatures.add("Paint Job"); 
     AudiFeatures.add("24inch Alloys"); 
      ProductOrder Audi = new ProductOrder ("Audi",  (String)cbxenginesize.getSelectedItem(), AudiFeatures, 9999.99); 

    //Create Car 
    ArrayList<String> BMWFeatures = new ArrayList<String>(); 
     BMWFeatures.add("SatNav"); 
     BMWFeatures.add("Leather Seats"); 
     BMWFeatures.add("22inch Alloys"); 
      ProductOrder BMW = new ProductOrder ("BMW", (String) cbxenginesize.getSelectedItem(), BMWFeatures, 10000.99); 

非常感謝。

+0

您應該閱讀關於如何在Java中使用數組的教程。 –

+1

看看java中的類,繼承,多態性它會幫助很多 – ismail

回答

0

之前,你甚至去填充一個JList ...

carmakes[] makes = new carmakes[3]; 
Audi [0] = new carmakes (AudiFeatures); 
BMW [1] = new carmakes (BMWFeatures); 

這需要AudiFeaturesBMWFeatures創建之後向下方法,直到進一步移動。它應該是更多的東西是這樣的:

carmakes[] makes = new carmakes[3]; 
carmakes [0] = new carmakes ("Audi", AudiFeatures); 
carmakes [1] = new carmakes ("BMW", BMWFeatures); 

或者你要使用HashMap而不是數組,這樣你可以看一下車讓的名字。

+0

謝謝,我確實這麼認爲,但是認爲在我調用數組列表之前它並不重要。我應該怎樣聲明數組[] int會工作嗎?還是應該是別的東西? – user3038486

+0

哦,親愛的,你真的*需要閱讀一個數組教程,並做一些簡單的練習,直到你更好地理解它們。這就像學習一門工藝 - 你必須先做出簡單的事情。 –