Can anybody help me to do a java awt program in which one frame opens another frame?

Many people here can, ask a specific question. Otherwise the answer is frame.setVisible(true) in an ActionListener.

Firstly, create the frame and set size/location and any other properties. Then make it visible as masijade posted above.

You would set the first frame as parent of the second frame.

Make this code execute in an action listener. For example, when someone clicks a button the second form could appear.

import javax.swing.*;


import java.awt.event.*;
public class second extends JFrame implements ActionListener {

		JButton button;
		JFrame frame;
		


		public second() {

			setLayout(null);
			setSize(500,500);

			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			 button = new JButton("click me");


			button.setBounds(90,300,50,50);
			button.addActionListener(this);
			add(button);

		}
			public void actionPerformed(ActionEvent e) {
				if(e.getSource() == button){
                                    frame = new JFrame();
					frame.setSize(500,500);
                                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                        frame.setVisible(true);



				}
			}

		}

create an object of the second class in a main and call the objectreference.setVisible(true) method and voila

fyi the second frame is the same size as the first but if you move it its there

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.