Click here to Skip to main content
12,700,966 members (29,320 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java
I am using eclipse and i am creating a Swing application which have two jframe, one is Login and second is welcome. i want to open the welcome jframe on clicking the submit button of login jframe. both the jframe are within the same package
Posted 22-Mar-13 2:30am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi Kapilkp,

Same time ago, I did something like that.

In login JFrame you must set the close operation as:


And when you click on the button, you have dispose this frame:


and create a new instance of your class that store the second JFrame

JSecondFrame secondFrame = new JSecondFrame();

I hope this helps you

Best regards,
Filipe Marques


import javax.swing.*;
import java.awt.event.*;
public class MyLogin {
	private JFrame f = new JFrame("Login");
	private JButton bok = new JButton("OK");
	public MyLogin() {
		bok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				new SecondFrame();
	public static void main(String[] args) {
		new MyLogin();

import javax.swing.*;
public class SecondFrame {
	private JFrame f = new JFrame("Second");
	public SecondFrame() {

The login JFrame is only a button and when you click it, the login window is disposed and the second window appears.
Kapilkp 22-Mar-13 7:46am
hi Filipe Marques, thanks for the help but it will be more helpful if you can tell me where i have to write these code under the ActionPerformed() section or some where else
Filipe Marques 22-Mar-13 8:27am
Kapilkp, I update my answer with a sample code. It does nothing, it's only to show you. (:
Kapilkp 3-Apr-13 3:22am
Filipe ,i am using eclipse that is why i am asking because on a notepad it is working but in eclipse it is not working
Filipe Marques 3-Apr-13 17:55pm
I never used eclipse. I use Netbeans or sometimes I use notepad++ with command line. But this is not relevant. You must have something similar with my code above. The unique difference that I can see is how eclipse create the button, but at the end, the result is the same. Best regards: Filipe

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100