Java program to connect two swing frames

      No Comments on Java program to connect two swing frames

Connect two swing frames

This program illustrate how to connect two swing frames.

Program

scan.java

import javax.swing.*;
import java.awt.event.*;
public class scan extends JFrame
{
	 JLabel l1;
 JButton b1;
 scan1 page;
scan()
{
l1=new JLabel("First page");
 l1.setBounds(190,80,100,100);
 b1=new JButton("Click here");
 b1.setBounds(155,150,100,30);
 
 b1.addActionListener(new ActionListener()
 {
	public void actionPerformed(ActionEvent e)
	{
		 
		page=new scan1();
		 page.setVisible(true);
	}	
 });
  add(b1);
 add(l1);
 
 setSize(500,500);
   setLayout(null);
 setVisible(true);

}
  public static void main(String arg[])
  {
  new scan();
  }
}

scan1.java

import javax.swing.*;
import java.awt.event.*;

public class scan1 extends JFrame
{
	JLabel l1;
	JButton b1;
 scan1()
   {
	    l1=new JLabel("Second page");
         l1.setBounds(190,80,100,100);
	   
	   b1=new JButton("Go back");
	   b1.setBounds(170,150,100,30);
	   
	   b1.addActionListener(new ActionListener()
	   {
		   public void actionPerformed(ActionEvent e)
		   {
			   scan s1=new scan();
			   s1.setVisible(true);
		   }
	   }
	   
	   );
	   
	   add(b1);
	   add(l1);
    setSize(500,500);
	setLayout(null);
	setVisible(true);
   }
   
   public static void main(String arg[])
  {
  new scan1();
  }
}

OUTPUT

Command

Connect two swing frames

Before click

Connect two swing frames

After click

Connect two swing frames


Comment below if you are facing any problem and subscribe to our newsletter for more updates.


Also read

Java program to change label text on button click
Java swing program to make signup form


Summary
Java program to connect two swing frames by scanfcode
Article Name
Java program to connect two swing frames by scanfcode
Description
This program illustrate how to connect two swing frames
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *