Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Im new to java and would be great if someone could just point me in the right direction here.

Im trying to put different arraylists into one array so i can then put those array objects into a Jlist.

I have got so far but now just cant seem to populate my Jlist with what i want.

Any Pointers would be great.

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

Many thanks.

share|improve this question
    
You should read a tutorial on how to use arrays in Java. –  Robin Green Nov 26 '13 at 22:42
1  
Have a look at classes, inheritance, polimorphism in java it will help a lot –  ismail Nov 26 '13 at 22:42

1 Answer 1

Before you even get to populating a JList...

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

This needs to be moved further down the method until after AudiFeatures and BMWFeatures have been created. And it should be something more like this:

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

or maybe you want to use a HashMap instead of an array, so that you can look up car makes by name.

share|improve this answer
    
Thanks i did think that, but thought it wouldn't matter until i called the array lists. What should i declare the array as will [] int work? or should it be something else? –  user3038486 Nov 26 '13 at 23:00
    
Oh dear, you really need to read an array tutorial, and do some simpler exercises until you understand them better. It's like learning a craft - you have to make simple things first. –  Robin Green Nov 26 '13 at 23:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.