SEE THIS link for the solution to the problem
I am doing a project where I have a drop down list, which when an option is selected on the list, it loads an applet with custom settings. The name of the main class of the applet is SteadyStateFusionDemo. I don't why I'm having so much trouble with this because I know that I have to use a ClassLoader, but quite frankly I don't know how to do this.
Here is the code for my dropdown list. I want to link from the option on the list to the other class.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.ClassLoader;
import ssfd.SteadyStateFusionDemo;
//**Creates Drop down Menu where choices show up in the box next to it//
//After one of these is selected, it loads the SteadyStateFusionDemo class//
//It also transmits a variable to the VariableStorage class, so that those//
//values can be used in operating the Tokamak.**//
public class ComboBox{
JComboBox combo;
JTextField txt;
public static void main(String[] args) {
ComboBox b = new ComboBox();
}
public ComboBox(){
String course[] = {"NSTX","LTX","ITER"};
JFrame frame = new JFrame("Creating a JComboBox Component");
JPanel panel = new JPanel();
combo = new JComboBox(course);
combo.setBackground(Color.gray);
combo.setForeground(Color.red);
txt = new JTextField(10);
panel.add(combo);
panel.add(txt);
frame.add(panel);
combo.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie){
String str = (String)combo.getSelectedItem();
//Where the ItemListener interprets the choice, and then loads the SteadyStateFusionDemo class.
if (str == "NSTX") {
txt.setText("A");
//loads SteadyStateFusionDemo, NSTX version
}
if (str == "ITER") {
txt.setText("B");
//loadsSteadyStateFusionDemo, ITER version
}
if (str == "LTX") {
txt.setText("C");
//loads SteadyStateFusionDemo, LTX version
}
There is more after this but it isn't relevant to the question.
Can someone help me figure out how to link the two classes? The second class is in a different package and it doesn't use a static method. I have practically looked all over the Internet to find the solution, but alas no luck. :(