Ti faccio vedere lo script per intero delle due classi:

Primo file:
codice:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;



public class TestCertificato
{
	public static void main(String[] args) throws NumberFormatException, IOException
	{

		boolean controllo = false;
		String input = null;
		while(!controllo){

			creaPannello panel = new creaPannello();

			try{


				int matricola = Integer.parseInt(input);
				controllo = true;
				}

			catch (NumberFormatException exception)
				{
				System.out.println("La matricola non e' un valore valido; riprova");

				}

						}
		stampaCertificato certificato = new stampaCertificato(input);
		System.exit(0);

	}


}

Secondo file:

codice:
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;


public class creaPannello extends JPanel
{

	public creaPannello()
	{
		frame = new JFrame();
		panel = new JPanel();
		campo = new JTextField(5);
		label = new JLabel("Inserisci qui la matricola");
		button = new JButton("Invia");


		ActionListener listener = new buttonPress();
		button.addActionListener(listener);

		panel.add(label);
		panel.add(campo);
		panel.add(button);
		frame.setContentPane(panel);
		frame.pack();
		frame.show();

	}

		class buttonPress implements ActionListener
		{
			public void actionPerformed(ActionEvent event)
			{
				valore = campo.getText();
			}
		}

	public String getValore()
	{
		return valore;
	}



private JFrame frame;
private JPanel panel;
private JTextField campo;
private JLabel label;
private JButton button;
private String valore;
}