e si hai ragione, io cancello proprio tutto.
ti posto il meccanisco che utilizzo per cambiare un pannello...
codice:
public TestaFrame() {
super("Versione 1.0");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Dimensione d2 = new Dimensione();
this.setPreferredSize(d2.DimensionePanel());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setVisible(true);
this.setResizable(true);
MenuLookDemo22 demo = new MenuLookDemo22();
this.setJMenuBar(demo.createMenuBar());
//adesso attacco al frame il pannello principale che sarà il cuore del programma
mainpanel = new MainPanel();
getContentPane().add(mainpanel, BorderLayout.CENTER);
getContentPane().validate();
//fine
}//fine testaframe
il menu invece fa questo
codice:
menuBar = new JMenuBar();
//Build the first menu.
menu = new JMenu("File");
menuBar.add(menu);
menuItemR = new JMenuItem("Salva Ricetta",
KeyEvent.VK_T);
menuItemR.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
mainpanel.salvaRicetta();
}//fine metodoVoid
});//fine actionlistener
menu.add(menuItemR);
menuItem = new JMenuItem("Esci",
KeyEvent.VK_T);
menuItem.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
System.exit(0);
}//fine metodoVoid
});//fine actionlistener
menu.add(menuItem);
menu = new JMenu("Inserisci");
menuBar.add(menu);
menuItem = new JMenuItem("Ingredienti",
KeyEvent.VK_T);
menuItem.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
getContentPane().remove(0);
menuItemR.setEnabled(false);
PanelIngredienti ingredienti = new PanelIngredienti();
getContentPane().add(ingredienti, BorderLayout.CENTER);
getContentPane().validate();
}//fine metodoVoid
});//fine actionlistener
menu.add(menuItem);
menu = new JMenu("Visualizza");
menuBar.add(menu);
menuItem = new JMenuItem("Zuccheri Puri",
KeyEvent.VK_T);
menuItem.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
getContentPane().remove(0);
menuItemR.setEnabled(false);
PanelZuccheriPuri zuccheriPuri = new PanelZuccheriPuri();
getContentPane().add(zuccheriPuri, BorderLayout.CENTER);
getContentPane().validate();
}//fine metodoVoid
});//fine actionlistener
menu.add(menuItem);
menu = new JMenu("Modifica");
menuBar.add(menu);
menuItem = new JMenuItem("Composizione Ingredienti Compositi",
KeyEvent.VK_T);
menuItem.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
getContentPane().remove(0);
menuItemR.setEnabled(false);
PanelZuccheriCompositi zuccheriCompositi = new PanelZuccheriCompositi();
getContentPane().add(zuccheriCompositi, BorderLayout.CENTER);
getContentPane().validate();
}//fine metodoVoid
});//fine actionlistener
menu.add(menuItem);
quindi come puoi vedere io rimuovo ogni volta un panel e ne inserisco un altro...