Hello,

I allready posted the question in a dutch forum but I got not a single answer, maybe this forum (wich has more users) wil be the answer of my question.

I making something that uses the MVC pattern.

first of al the model:

this is 1 class (and 1 class for an exception)

Code:
/**
 * 
 */
package testprogram.model;


/**
 * @author ikke
 *
 */
public class TestModel {
	
	private int amountOfPeople;
	private int maxAge;
	private String uit;
	
	public TestModel(int m, int l) throws TooSmallException {  
		if (m < 1) {
			throw new TooSmallException("It must be at least 1.");
		}
        
		if (l <= 0)
		{
			throw new TooSmallException("Age must be greater then 0.");
		}
        
		this.amountOfPeople = m;
		this.maxAge = l;
	}
	
	public void GenereerData () {	
		this.uit = "There are " + this.amountOfPeople + " people, with a maximum age of " + this.maxAge + " year";
		System.out.println(this.uit);
	}
	
	public void setAantalMensen(int m) throws TooSmallException {	
		if (m < 1) {
			throw new TooSmallException("It must be at least 1.");
		}
		this.amountOfPeople = m;		
	}
	
	public int getAantalMensen() {
		return this.amountOfPeople;
	}
	
	public void setMaxLeeftijd (int l) throws TooSmallException {	
		if (l <= 0)
		{
			throw new TooSmallException("age must be greater then 0.");
		}
		this.maxAge = l;
	}
	
	public int getMaxLeeftijd() {
		return this.maxAge;
	}

	public String Oplossing() {
		return this.uit;
	}

	
	/**
	 * Commandline version
	 * @param args
	 * @throws TooSmallException 
	 */
	public static void main(String[] args) throws TooSmallException {
		
		TestModel test = new TestModel(25, 60);
		test.GenereerData();
	}

}
the exception class:
Code:
package testprogram.model;

public class TooSmallException extends Exception {
	
	/**
	 * Constructor voor een NegativeValueException.
	 * @param errorTekst een String met een pasende omschrijving
	 * van de situatie.
	 */
	public TooSmallException(String errorTekst){
		super(errorTekst);
	}	
}
That about the model, in the TestModel class there is a Main class that works for the command line.

Now the views.
The views are 3 seperate panels that come together on a frame. These are 4 seperate classes, and they must stay seperate.

The classes are:
ButtonPanel: This class puts 2 buttons on a JPanel (1 for generate, and 1 for cancel)
SpinnerPanel: This class puts 2 spinners on a JPanel
OutputPanel : this class shows the output on a textarea
MainFrame: the 3 panels come together on a JFrame, this class holds also the main class for the gui.

Code:
/**
 * 
 */
package testprogram.view;

import javax.swing.JButton;
import javax.swing.JPanel;

import testprogram.controllers.Exitlistener;


/**
 * @author ikke
 * Class that puts 2 buttons on a panel.
 *
 */
public class ButtonPanel extends JPanel {
	
	//aanmaken van de knoppen
	private JButton btnGenerate;
	private JButton btnCancel;
	
	public ButtonPanel() {
		
		//declareren van de knoppen
		this.btnGenerate = new JButton("Genereren");
		this.btnCancel = new JButton("Cancel");
		
		//toevoegen aan de panel
		this.add(this.btnGenerate);
		this.add(this.btnCancel);
		
		//listener van de Cancel knop
		this.btnCancel.addActionListener(new Exitlistener());
	}
}
Code:
/**
 * 
 */
package testprogram.view;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

/**
 * @author ikke
 * Class that makes 2 spinners
 *
 */
public class SpinnerPanel extends JPanel {

	//aanmaken van de spinners
	public JSpinner spnrPeople;
	public JSpinner spnrAge;
	
	//aanmaken van de labels
	private JLabel lblPeople;
	private JLabel lblAge;
	
	public SpinnerPanel() {
		
		//declareren van de spinners met bijhorende labels en instellen van de spinners
		this.lblPeople = new JLabel("number of people");
		this.lblAge = new JLabel("Maximum age");
		this.spnrPeople = new JSpinner();
		this.spnrAge = new JSpinner();
		this.spnrPeople.setModel(new SpinnerNumberModel(100, 1, 1000, 1));
		this.spnrAge.setModel(new SpinnerNumberModel(60, 0, 120, 1));
		
		//toevoegen aan de panel
		this.add(this.lblPeople);
		this.add(this.spnrPeople);
		this.add(this.lblAge);
		this.add(this.spnrAge);	
	}	
}
Code:
/**
 * 
 */
package testprogram.view;

import javax.swing.JPanel;
import javax.swing.JTextArea;

/**
 * @author ikke
 * Class that shows the output in a textarea
 *
 */
public class OutputPanel extends JPanel {
	
	private JTextArea output;
	
	public OutputPanel() {
		
		//declareren van de textarea
		this.output = new JTextArea("Here must be the string that gets generated.");
		
		//toevoegen aan de panel
		this.add(this.output);
		
	}

}
Code:
/**
 * 
 */
package testprogram.view;

import java.awt.BorderLayout;

import javax.swing.JFrame;


/**
 * @author ikke
 * Class that puts the 3 JPanels on a JFrame
 *
 */
public class MainFrame extends JFrame {
	
	//atributen aanmaken
	private ButtonPanel buttons = new ButtonPanel();
	private SpinnerPanel spinners = new SpinnerPanel();
	private OutputPanel uit = new OutputPanel();
	
	public MainFrame(String titel) {
		
		super(titel);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setLocation(200, 200);
		
		//toevoegen van de panels
		this.add(this.buttons, BorderLayout.SOUTH);
		this.add(this.uit, BorderLayout.CENTER);
		this.add(this.spinners, BorderLayout.NORTH);
		
		//alles samenvoegen en ervoor zorgen dat er aan de frame niets veranderd kan worden
		this.pack();
		this.setResizable(false);
		this.setVisible(true);
	}
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new MainFrame("This is just an example.");
	}

}
The problem that I have is implementing the listeners.
The meaning is that i have to set the number of people with a JSpinner and also the maximum age.
And when i press the Generete button, the text on the textarea must change with the amount of people and the maximum age.
The only listener that gives me no problem is the listener for the cancel butten there is only holds System.exit(0);

Can someone help me with the listeners please?

Sorry for the long text and huge lot of code.

In case someone wants the code, ask it, and I will put the source code in zipformat.


greetings,
Sven