Results 1 to 14 of 14
  1. #1
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default Arraylist with arrays?

    Hi all,

    For a school assignment i need to make a program that involves creating new customers with several info(adress, customer info, ect...) now i was thinking about making an arraylist with arrays in it. So when i add a new customer there will be a new array made within the arraylist.

    Is this posisble or is there another way to create new customers and put them in an array without overriding the excisting array(s) and without using a database?

    thanks in advance,

    Dieter

  2. #2
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    You need to create Customer class which will contain all info about a customer. Then you will use list of Customer objects.
    Try Controls4J - Advanced Swing Components.

  3. #3
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    No shit, i allready got that. i was asking i there was another way then using an arraylist with arrays to display it easly into (for exemple) in a textarea. If there is an easier way to add new customers to the program using the arraylist.

  4. #4
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    Could you post some parts of your code there?
    Try Controls4J - Advanced Swing Components.

  5. #5
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    sure, well the code isnt finished yet but i'v got some code that i was thinking about on how to use it

    just some info: my code is dutch so i'm too lazy to translate it.

    Baasje = the Customer and is my class name.
    and the txt are just the info they enter of the customer.

    Java Code:
    public ArrayList<Baasje> baasjes = new ArrayList<Baasje>();
        
    
    private void btnAddBaasjeActionPerformed(java.awt.event.ActionEvent evt) {                                             
            if(txtNaamBaasje.getText().equals("") || txtVoornaam.getText().equals("") || txtRijksNrBaasje.getText().equals("") || txtGemeente .getText().equals("") || txtLand.getText().equals("") || txtNr.getText().equals("") || txtPostcode.getText().equals("") || txtProvincie.getText().equals("") || txtStraat.getText().equals("")){
                JOptionPane.showMessageDialog(this, "Gelieve alle verplichte velden in te vullen.", "Foutmelding", JOptionPane.WARNING_MESSAGE);
            }else{
                
                if(txtTelefoon.getText().equals("") && txtGsm.getText().equals("")) {
                    JOptionPane.showMessageDialog(this, "U heeft reeds 20 baasjes aangemaakt.", "Foutmelding", JOptionPane.INFORMATION_MESSAGE);
                    Contactgegevens tempGeg = new Contactgegevens(txtStraat.getText(), txtNr.getText(), txtGemeente.getText(), txtProvincie.getText(), txtLand.getText(), Integer.parseInt(txtPostcode.getText()));
    
                    Baasje tempBaasje = new Baasje(txtNaamBaasje.getText(), txtVoornaam.getText(), ((cmbGeslachtBaasje.getSelectedIndex()==0)?(true):(false)), Integer.parseInt(txtRijksNrBaasje.getText()), dieren, tempGeg);
                    //baasjes.add(tempBaasje);
                    baasjes.add(tempBaasje);
                }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Dieter View Post
    No ****, i allready got that.
    I think that this wasn't obvious from your initial post.
    i was asking i there was another way then using an arraylist with arrays to display it easly into (for exemple) in a textarea. If there is an easier way to add new customers to the program using the arraylist.
    You don't need arraylists for displaying. Just simply use the arraylist of customer, that you already have. If you are still unsure of what you need to do, then please clarify the problem even more, and post a small bit of compilable and runnable code (not the whole program if this can be avoided).

  7. #7
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    No, this is usual way. You can just simlpify your code and make it more elegant. For example:

    ((cmbGeslachtBaasje.getSelectedIndex()==0)?(true): (false)) you can use cmbGeslachtBaasje.getSelectedIndex()==0.

    Move this conditionin method:
    txtNaamBaasje.getText().equals("") || txtVoornaam.getText().equals("") || txtRijksNrBaasje.getText().equals("") || txtGemeente .getText().equals("") || txtLand.getText().equals("") || txtNr.getText().equals("") || txtPostcode.getText().equals("") || txtProvincie.getText().equals("") || txtStraat.getText().equals("")

    Java Code:
    private boolean isAnyEmpty() {
    return txtNaamBaasje.getText().equals("") || txtVoornaam.getText().equals("") || txtRijksNrBaasje.getText().equals("") || txtGemeente .getText().equals("") || txtLand.getText().equals("") || txtNr.getText().equals("") || txtPostcode.getText().equals("") || txtProvincie.getText().equals("") || txtStraat.getText().equals("");
    }
    BTW, you can implement custom binding framework similar to binding in GXT. But it can be overkill for your case.
    Try Controls4J - Advanced Swing Components.

  8. #8
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    Ok cheers for the help.
    i hopefully go it now only i'm struggling with my comboboxes, for somereason when i add an element to the combobox index it shows the element twice.

    here is my code for it:

    Java Code:
       private Object makeObj(final String item)  {
            return new Object()
            {
    
    private void cmbCategorieItemStateChanged(java.awt.event.ItemEvent evt) {                                              
            switch(cmbCategorie.getSelectedIndex()) {
                case 0:
                    cmbSubcategorie.removeAllItems();
                    cmbSubcategorie.addItem(makeObj("Voornaam"));
                    cmbSubcategorie.addItem(makeObj("Naam"));
                    cmbSubcategorie.addItem(makeObj("Rijksregisternummer"));
                    cmbSubcategorie.addItem(makeObj("Geslacht"));
                    break;
                case 1:
                    cmbSubcategorie.removeAllItems();
                    cmbSubcategorie.addItem(makeObj("Registratienummer"));
                    cmbSubcategorie.addItem(makeObj("Geslacht"));
                    cmbSubcategorie.addItem(makeObj("IngeŽnt"));
            }
        }

    am i doing someting wrong?

  9. #9
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    Crazy code. What do you need to do?
    Try Controls4J - Advanced Swing Components.

  10. #10
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    if i select an item from the combobox categorie it adds it to combobox subCategorie.

    Case 0 and Case 1 are 2 elements in the Categorie combobox

  11. #11
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    I think that the problem is in calling makeObj for creation objects fot the second list. BTW, why do you need anonimous class? This code can be simpler.
    Try Controls4J - Advanced Swing Components.

  12. #12
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

    You think? i don't know any simpler way for doing this, only way i found is this way. I will do some more research then.

    Thanks for your time and effort you did for the reply's you did. means alot to me :)

    rep ++ for you ;)

    Dieter
    Last edited by Dieter; 09-19-2009 at 10:31 PM.

  13. #13
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    Thanks :-)

    I think that it will help you:

    PHP Code:
    public class F extends JFrame {
        private JComboBox jComboBox1;
        private JComboBox jComboBox2;
    
        public F() throws HeadlessException {
            getContentPane().setLayout(new FlowLayout());
            initComponents();
    
            pack();
            setLocationRelativeTo(null);
        }
    
        private void initComponents() {
            jComboBox1 = new JComboBox(new Integer[] {1, 2});
            jComboBox1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Integer item = (Integer) jComboBox1.getSelectedItem();
    
                    DefaultComboBoxModel model = (DefaultComboBoxModel) jComboBox2.getModel();
                    model.removeAllElements();
    
                    if (item.intValue() == 1) {
                        model.addElement("A");
                        model.addElement("B");
                    } else if (item.intValue() == 2) {
                        model.addElement("C");
                        model.addElement("D");
                    }
                }
            });
    
            getContentPane().add(jComboBox1);
    
            jComboBox2 = new JComboBox();
            getContentPane().add(jComboBox2);
        }
    
        public static void main(String[] args) {
            new F().setVisible(true);
        }
    }
    Try Controls4J - Advanced Swing Components.

  14. #14
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

Similar Threads

  1. 2D Arrays
    By Major90 in forum New To Java
    Replies: 6
    Last Post: 11-06-2008, 03:08 PM
  2. Need help with Arrays
    By dietgal in forum New To Java
    Replies: 21
    Last Post: 10-08-2008, 02:59 PM
  3. Help with Arrays
    By bri1547 in forum New To Java
    Replies: 4
    Last Post: 08-01-2008, 06:12 AM
  4. Replies: 2
    Last Post: 04-21-2008, 12:43 PM
  5. arrays help
    By Warren in forum New To Java
    Replies: 6
    Last Post: 11-23-2007, 08:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •