4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by javanub123
0

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

0

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.

Edited by leiger: n/a

0
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

Edited by javanub123: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.