Una cosa del genere??
codice:
import java.awt.*;
import javax.swing.*;
public class TestFrame extends JFrame
{
private CardLayout cardLayout;
private JPanel cardPanel;
public TestFrame ()
{
super ("Test Frame");
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
cardLayout = new CardLayout ();
cardPanel = new JPanel ();
cardPanel.setLayout (cardLayout);
cardPanel.add (new Pannello1 (), "pannello1");
cardPanel.add (new Pannello2 (), "pannello2");
getContentPane().add (cardPanel);
pack ();
}
public void selectPanelAsk ()
{
JRadioButton radio1 = new JRadioButton ("Pannello 1");
JRadioButton radio2 = new JRadioButton ("Pannello 2");
ButtonGroup buttonGroup = new ButtonGroup ();
buttonGroup.add (radio1);
buttonGroup.add (radio2);
Object[] message = { "Quale pannello vuoi?", radio1, radio2 };
JOptionPane.showMessageDialog (this, message, "Selezione pannello", JOptionPane.QUESTION_MESSAGE);
if (radio1.isSelected ())
cardLayout.show (cardPanel, "pannello1");
else if (radio2.isSelected ())
cardLayout.show (cardPanel, "pannello2");
}
public static void main (String[] args)
{
SwingUtilities.invokeLater (new Runnable ()
{
public void run ()
{
TestFrame f = new TestFrame ();
f.setVisible (true);
f.selectPanelAsk ();
}
});
}
}
class Pannello1 extends JPanel
{
public Pannello1 ()
{
setBackground (Color.YELLOW);
setPreferredSize (new Dimension (300, 300));
}
}
class Pannello2 extends JPanel
{
public Pannello2 ()
{
setBackground (Color.RED);
setPreferredSize (new Dimension (300, 300));
}
}