Hi, i am new to this forum, and also new to JAVA, at the moment i have an assignment in which i am desperately in need of help.

I don't know much about MVC and i was wondering if there is any one out there that could help me.

regards.

Dani AI

Generated

For — a compact, practical primer tied to the thread so far (given 's prompt and ' book suggestion). This is a hands‑on view of MVC for a Java assignment and a short checklist to implement it cleanly.

Model, View, Controller — what each should do and how they interact:

  • Model: holds data and business rules. It does not know about Swing or web frameworks. It publishes changes via events/listeners.
  • View: renders model state and subscribes to model events. No business logic here; only presentation and simple formatting.
  • Controller: receives user input (button clicks, HTTP requests), translates that into model calls, and may update views.
    Typical flow: View -> Controller -> Model -> (model fires events) -> View updates.

A simple implementation checklist and minimal example:

  • Keep the model free of GUI imports.
  • Use PropertyChangeSupport or a small listener interface to notify views.
  • Have views update only on the Event Dispatch Thread (SwingUtilities).
  • Controllers wire view controls to model methods; keep them thin.
  • Run long-running tasks off the EDT (SwingWorker).

Example model snippet:

public class CounterModel {
  private int count;
  private PropertyChangeSupport pcs = new PropertyChangeSupport(this);

  public void addPropertyChangeListener(PropertyChangeListener l) { pcs.addPropertyChangeListener(l); }
  public void increment() { int old = count; count++; pcs.firePropertyChange("count", old, count); }
  public int getCount() { return count; }
}

Common pitfalls: putting business logic in the view, failing to fire change events, and doing blocking work on the EDT. For general background see Model–view–controller. For Java specifics, the JavaDoc for PropertyChangeSupport and the Oracle Swing concurrency tutorial are practical references.

Recommended Answers

All 2 Replies

Help you with what?

Try the book 'head first design patterns'. It has a clear layout of the model view controller pattern (which is fairly hard to really grasp in the start, in my opinion).

The book should tell you a bit more though, and there are more pages about design patterns. Give it a whirl :p

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.