Knute Snortum wrote:
Or should i use a arraylist getter and create a variable in the frame based on the getter and then use the for loop in the frame.
If I'm understanding you, this sounds correct. Assuming that StudentenAdministratie can be instantiated in StudentAdminFrame. You need to be able to access opleidingen from the StudentAdminFrame class, something like:
Notes: this is not a good design, but I get the feeling you just want to get this assignment over with. At some point you should come back to this a design it better. We can talk about that later if you want.
Also, I don't have your latest code, or the complete code, as there is no main() in any class and I don't think you are using a framework.
Knute Snortum wrote:How about passing in your combo box and using:
Knute Snortum wrote:What exactly are you stuck on now?
Knute Snortum wrote:I believe you need to either add the items to your combo box one by one...
...or add them all when you create the combo box:
(The method name "getOpleidingen" is not a good one; I'd call it something like "convertOpleidingenToArray".)
But it would be even better if you could add the Opleidingen objects themselves. (Opleidingen would need a good toString() method):
Piet Souris wrote:I see...
Well, have a look at your latest method. You have this line in your loop:
and when the loop is over, you return this 'test'. No wonder you only see the last one!
I suggest you change this method into something like:
Edit: oops, I should have read a little better. What exactly are your needs? Do you have one combined List<Studie> and do you need to get that plitted into a List<Opleiding> and a List<CPP>? If so, then 'instanceof' works well.
Creating a JComboBox is then also easy, just add (in a loop), all the elements of one of these Lists into your box. unfortunately, a JComboBox only has constructors that take either an array or a Vector.
Hope I'm a bit clearer, now.
Piet Souris wrote:hi Iwan,
Regarding your question about these comboboxes:
an easy way to get these boxes filled without looping is something like:
List<Opleiding> opleidingen = ...;
...
JComboBox<Opleiding> comboOpleiding = new JComboBox<>(opleidingen.stream().toArray(Opleiding[]::new));
// or new JComboBox<>(new Vector<>(opleidingen));
You need a decent toString() method though.
If you ever change one of those Studie-lists, then there are nice ways to inform the comboboxes of these changes. But that for later.
Knute Snortum wrote:I would loop through opleidingen and add each item with a opleidingen.get(index).
Piet Souris wrote:hi Iwan,
Well, the assignment is there, and I hope that Google's work is good enough for those poor ones who do not speak Dutch! Important is that it is about inheritance and dynamic binding.
A question: now that your NPE is solved, are you satisfied with what you have so far? Does it fullfill the assignment? And that is apart from the GUI, just the classes and the interfaces concerning the Studies and the Students (and the administration, of course).
Carey Brown wrote:Out of curiosity, what does CPP mean/stand for ?
Carey Brown wrote:Please don't quote huge blocks of text if you can help it.
Carey Brown wrote:From Google Translate:
Here is the assingment:
.
Piet Souris wrote:hi Iwan,
indeed I am from Holland. Can you put that assignment here in this topic? We can translate all that's necessary, if someone asks for it.