La mia domanda potrebbe risultare banale, ma per me che sono alle prime armi con Java risulta un grattacapo.

Ho pensato ad un esercizio :

Cambiare il titolo di un JFrame al click di un pulsante.



public static void main(String[] args)
{
ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.show();
}
}//creo la classe per il frame :
public ButtonFrame()
{

setTitle("");
setSize(WIDTH, HEIGHT);

// aggiungo panel al frame

PannelloTitoli panel = new PannelloTitoli(/*Se uso this.getName() passo frame */);
Container contentPane = getContentPane();
contentPane.add(panel);
}

public static final int WIDTH = 300;
public static final int HEIGHT = 200;

}

//creo il pannello
class PannelloTitoli extends JPanel implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
// this.setBackground(Color.yellow);

this.mCambiaTitolo("Ciao");
}
public void mCambiaTitolo(String nomec2)
{
// myObj = new Object();
Object myObj = (Object)nomec2;
ButtonFrame myObj2 = (ButtonFrame)myObj;
myObj2.setTitle("Titolo");

}
public PannelloTitoli(Object whatframe)
{
String nomeclasse = new String(whatframe.toString());
JButton titolouno = new JButton("Titolo 1");
JButton titolodue = new JButton("Titolo 2");
JButton titolotre = new JButton("Titolo 3");
//aggiundo i pulsanti appena creati
add(titolouno);
add(titolodue);
add(titolotre);


/**Associo i bottoni al pannello (this) */
titolouno.addActionListener(this);
titolodue.addActionListener(this);
titolotre.addActionListener(this);

//private String nomeclasse;

}




// Non riesco a passare ed agire sul frame in cui risede il pannello
// Come faccio a passare alle classe che fa sia da pannello che
// da rilevatore il frame in cui risede ??