import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.util.List; public class GUIController { private static final int ANTALL = 9; private BigramModel model; private GUIView view; public GUIController(BigramModel model, GUIView view) { this.model = model; this.view = view; } public int start(String filNavn) { try { model.les(filNavn); } catch (IOException e) { view.visFeil("Feil med filen " + filNavn); return 1; } if (model.erTom()) { view.visFeil("Filen " + filNavn + " er tom"); return 2; } model.reset(); oppdater(); return 0; } private void oppdater() { view.visOrd(model.hentOrd()); List ordListe = model.hentNesteOrdListe(ANTALL); if (ordListe != null) { class OrdlisteKnapper implements ActionListener { @Override public void actionPerformed(ActionEvent e) { String ord = e.getActionCommand(); model.leggTilSetning(ord); oppdater(); } } view.visOrdValgListe(ordListe, new OrdlisteKnapper()); } else { oppdater(); } view.oppdaterSetning(model.hentSetning()); } }