questo è un esempio molto spartano di come potresti risolvere il tuo problema
codice:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* @author marialaura
*
*/
public class DueJFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
private JFrame jFrame1 = null; // @jve:decl-index=0:visual-constraint="358,10"
private JPanel jContentPane1 = null;
private JButton jButton1 = null;
/**
* This is the default constructor
*/
public DueJFrame() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setResizable(false);
this.setPreferredSize(new Dimension(300, 200));
this.setMinimumSize(new Dimension(300, 200));
this.setMaximumSize(new Dimension(300, 200));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBackground(Color.white);
this.setContentPane(getJContentPane());
this.setTitle("Primo");
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridheight = 1;
gridBagConstraints.gridwidth = 1;
gridBagConstraints.insets = new Insets(5, 5, 5, 5);
gridBagConstraints.ipadx = 5;
gridBagConstraints.ipady = 5;
gridBagConstraints.gridy = 0;
jContentPane = new JPanel();
jContentPane.setLayout(new GridBagLayout());
jContentPane.setBackground(Color.white);
jContentPane.add(getJButton(), gridBagConstraints);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
try {
jButton = new JButton();
jButton.setFont(new Font("Tahoma", Font.BOLD, 14));
jButton.setText("PROSSIMO");
jButton.setPreferredSize(new Dimension(150, 30));
jButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
prossimo();
}
});
} catch (java.lang.Throwable e) {
e.printStackTrace();
}
}
return jButton;
}
/**
* This method initializes jFrame1
*
* @return javax.swing.JFrame
*/
private JFrame getJFrame1() {
if (jFrame1 == null) {
try {
jFrame1 = new JFrame();
jFrame1.setBounds(new Rectangle(0, 0, 300, 200));
jFrame1.setBackground(Color.white);
jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame1.setMaximumSize(new Dimension(300, 200));
jFrame1.setMinimumSize(new Dimension(300, 200));
jFrame1.setPreferredSize(new Dimension(300, 200));
jFrame1.setTitle("Secondo");
jFrame1.setResizable(false);
jFrame1.setContentPane(getJContentPane1());
} catch (java.lang.Throwable e) {
e.printStackTrace();
}
}
return jFrame1;
}
/**
* This method initializes jContentPane1
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane1() {
if (jContentPane1 == null) {
try {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.insets = new Insets(5, 5, 5, 5);
gridBagConstraints1.ipadx = 2;
gridBagConstraints1.ipady = 2;
gridBagConstraints1.gridy = 0;
jContentPane1 = new JPanel();
jContentPane1.setLayout(new GridBagLayout());
jContentPane1.setBackground(Color.white);
jContentPane1.add(getJButton1(), gridBagConstraints1);
} catch (java.lang.Throwable e) {
e.printStackTrace();
}
}
return jContentPane1;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
try {
jButton1 = new JButton();
jButton1.setFont(new Font("Tahoma", Font.BOLD, 14));
jButton1.setPreferredSize(new Dimension(150, 30));
jButton1.setText("INDIETRO");
jButton1.setMnemonic(KeyEvent.VK_UNDEFINED);
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
indietro();
}
});
} catch (java.lang.Throwable e) {
e.printStackTrace();
}
}
return jButton1;
}
private void prossimo() {
// disabiliti il primo
this.setEnabled(false);
// mostri il secondo frame
getJFrame1().setVisible(true);
}
private void indietro() {
// abilito il primo
this.setEnabled(true);
// nascondo il sencondo
getJFrame1().dispose();
}
public static void main(String[] args) {
new DueJFrame();
}
}
spero ti possa aiutare.