Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating an array of Classes
    primarykey
    data
    text
    <p>OK the issue that I'm working on is creating a Wizard for a program I'm building. Bare with me this is a somewhat long winded explination as i need to explain the setup.</p> <p>I currently have three class that combine together to build a wizard frame and display all the panels that are need to collect all the relevant information for creating a new item. </p> <p>the first is an abstract extension of JPanel so that certain values and methods are always available, each class that extended the below would have its own unique constructor for passing in the data required to fill in various comboboxes, lists etc.</p> <pre><code>public abstract class baseWizPanel extends JPanel { protected boolean isValid = false; protected final int lblWidth = 85; public baseWizPanel(String Name) { setLayout(new BorderLayout(0, 0)); JLabel lblStepName = new JLabel(Name); } public abstract boolean isDataValid(); public abstract void validate(); public abstract String getMessage(); } </code></pre> <p>the second is a class that collects that baseWizardPanel together with a name, this will be used to store other things in a future release. Just in case your wondering why even have it.</p> <pre><code>public class WizardStep { private String Name; private baseWizPanel pnlToAdd; public &lt;T extends baseWizPanel&gt; WizardStep(String n, T p) { this.Name = n; this.pnlToAdd = p; } public String getName() { return this.Name; } public Component getPanel() { return this.pnlToAdd; } } </code></pre> <p>The last class is a extension of JDialog that brings all the pieces together and presents them to the user as a step by step process.</p> <p>Previously I'd been using implementing my wizard in a fashion similar to this.</p> <ol> <li>Load all the relevant data.</li> <li>Create an ArrayList of WizardStep </li> <li>build the array using ArrayList.add(new WizardStep("name", new baseWizPanel(arguments)));</li> <li>Load Wizard class and display</li> </ol> <p>This works fine to create the wizard and display it to the user. What i want to do now is using a generic data load function that i've built to keep all the loading of data in one place, i need to be able to create the wizard from an ArrayList of classes.</p> <p>so i want to go </p> <pre><code>public class loadData { loadData(ArrayList&lt;class&gt; classestoload) dataset1 = load data from data source dataset2 = load data from data source dataset3 = load data from data source dataset4 = load data from data source dataset5 = load data from data source for each class in classestoload { create class if class = class1 { use class1 constructor with dataset 1 &amp; 2 } if class = class2 { use class1 constructor with dataset 5 } if class = class3 { use class1 constructor with dataset 2 &amp; 3 } if class = class4 { use class1 constructor with dataset 4 &amp; 5 } } } </code></pre> <p>I can use the code from <a href="https://stackoverflow.com/questions/1268817/create-new-class-from-a-variable-in-java">Create new class from a Variable in Java</a> to create the class I need but to use the constructors and pass the correct data I need to know the class, I could use instanceof but everything I've read says this isn't a good choice.</p> <p>Now my question is what should I do here so that I either don't have to use instanceof or what should I use instead of instance of?</p> <p>I hope I've explained that properly and I apologise if I haven't.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload