/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /* ein schlechtes Beispiel fuer ein model-view-cotroller Programm * die Eingaben (controller), die Verarbeitung (model) * und die Ausgaben (view) sind beliebig vermischt. */ import java.applet.Applet; import java.awt.Button; import java.awt.Label; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; //-------------------- public class ModelViewController0 extends Applet { Button control1, control2; int model; Label view; //-------------------- public void init() { //-------------------- // die MVC Bestandteile initialisieren control1 = new Button("+1"); control1.setBackground(Color.orange); control2 = new Button("-1"); control2.setBackground(Color.pink); model = 0; view = new Label(); view.setAlignment(Label.CENTER); view.setBackground(Color.gray); view.setText("0"); //-------------------- // die grafischen Objekte anordnen setLayout(new GridLayout(3,1)); add(control1); add(control2); add(view); //-------------------- // die controller Ereignisse behandeln control1.addActionListener (new ActionListener() { public void actionPerformed(ActionEvent e) { ++model; view.setText("" + model); } } ); control2.addActionListener (new ActionListener() { public void actionPerformed(ActionEvent e) { --model; view.setText("" + model); } } ); } }