0

I need help in the running of the following Java program. I want the main program to pause running after it displays a new JFrame form and resume after the new window is closed ( or Next button is clicked ) .

So The 10 Forms should come sequentially after I press the next button not altogether at once!

MainClass.java

public class MainClass {
void Run()
{
    for(int i=0;i<10;i++)
        new NewForm().setVisible(true);
}

public static void main (String[] args)
{
    new MainClass().Run();
}
}

NewForm.java

public class NewForm extends javax.swing.JFrame {

    public NewForm() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jButton1.setText("Next");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(155, 155, 155)
                .addComponent(jButton1)
                .addContainerGap(190, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(131, 131, 131)
                .addComponent(jButton1)
                .addContainerGap(146, Short.MAX_VALUE))
        );

        pack();
    }
   public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewForm().setVisible(true);
            }
        });
    }
    private javax.swing.JButton jButton1;              
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Sidharth V
  • 181
  • 3
  • 13

1 Answers1

0

Setting jframe visible will not wait until the jframe is closed, thats why 10 jframes pops at you. You need to display just one, then add a ActionLisetener to your button. In this action, you just close your panel and open onother one. Of coursce you will need some global counter, consider making i static for start.

kajacx
  • 12,361
  • 5
  • 43
  • 70