I got a small Problem with a JComboBox and the MCV Pattern.
In my View package i got a class gui. This contains the combobox.
package view;
public class Gui {
.........
public JComboBox<OceanObject> oceanBoxDelete = new ComboBox<OceanObject>
();
this.down.add(this.oceanBoxDelete);
this.oceanBoxDelete.setSize(40, 1);
.......
This also contains a button. If the button gets hit it triggers a swith trough a button listener/action listener. This switch is supposed to trigger a procedure with removes an object from the list. If i put the action listener into the same java file it works but I'm not allowed to do so. If i put it into the button listener file i get an null pointer exeception when entering the combobox with the comment unknown source and .
My button listener looks like:
package control;
import view.Gui;
public class ButtonListener implements ActionListener{
private Gui gui;
public ButtonListener() {
this.ocean = ocean;
}
@Override
public void actionPerformed(ActionEvent ae) {
switch (ae.getActionCommand()) {
....
case "Delete":
System.out.println("deleteButton wurde gedrueckt.");
OceanObject oObject = (OceanObject)
gui.oceanBoxDelete.getSelectedItem());
go.removeOceanOjectFromOcean(oObject);
.......
I can see that the right switch is triggered since the println is displayed right in the console.
So i think the problem is that the problem is, that the getSelectedItem cant see the combobox and i need to make it known to it, but how?