Results 1 to 14 of 14
Thread: Arraylist with arrays?
- 09-19-2009, 11:39 AM #1
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
- 09-19-2009, 02:19 PM #2
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
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.
- 09-19-2009, 02:22 PM #3
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.
- 09-19-2009, 02:42 PM #4
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
- 09-19-2009, 03:17 PM #5
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); }
-
I think that this wasn't obvious from your initial post.
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).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.
- 09-19-2009, 04:18 PM #7
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
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("")
BTW, you can implement custom binding framework similar to binding in GXT. But it can be overkill for your case.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(""); }Try Controls4J - Advanced Swing Components.
- 09-19-2009, 04:36 PM #8
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?
- 09-19-2009, 05:11 PM #9
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
- 09-19-2009, 07:03 PM #10
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
- 09-19-2009, 09:22 PM #11
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
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.
- 09-19-2009, 09:27 PM #12
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 ;)
DieterLast edited by Dieter; 09-19-2009 at 09:31 PM.
- 09-19-2009, 10:03 PM #13
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
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.
- 09-19-2009, 11:10 PM #14
Similar Threads
-
2D Arrays
By Major90 in forum New To JavaReplies: 6Last Post: 11-06-2008, 02:08 PM -
Need help with Arrays
By dietgal in forum New To JavaReplies: 21Last Post: 10-08-2008, 01:59 PM -
Help with Arrays
By bri1547 in forum New To JavaReplies: 4Last Post: 08-01-2008, 05:12 AM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
arrays help
By Warren in forum New To JavaReplies: 6Last Post: 11-23-2007, 07:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks