I'm implementing an application using MVC pattern, In some cases I have created model and controller from the view, and called the appropriate method of the controller inside the view. Is this a design issue, if so what could be the solution, I can't crate all my models in the main because some of them are invoked by a click from the GUI.
here is an example code:
public class MyView extends JInternalFrame{
private JComboBox<String> myList;
private JButton button;
public MyView(){
super("MyView", true, // resizable
false, // closable
false, // maximizable
true);// iconifiable
setSize(250, 150);
setLocation(300,300);
myList= new JComboBox<String>();
button= new JButton("Click");
button.addActionListener(new Listener());
JLabel label = new JLabel("Example");
Border lineBorder = BorderFactory.createTitledBorder("Example UI");
JPanel panel= new JPanel();
panel.setBorder(lineBorder);
panel.setLayout(new GridLayout(3, 1));
panel.add(label);
panel.add(list);
panel.add(button);
add(panel);
}
class Listener implements ActionListener{
@Override
public void actionPerformed(ActionEvent actionEvent) {
String button = actionEvent.getActionCommand();
if(button==button.getText()){
Model model = new Model ();
Controller controller = new Controller (model, MyView.this);
controller.doSomething();
}
}
}