Click here to Skip to main content
Rate this: bad
good
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 1:30am
Kapilkp353

1 solution

Rate this: bad
good
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:
 
f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
 
And when you click on the button, you have dispose this frame:
 
dispose();
 

and create a new instance of your class that store the second JFrame
 
dispose();
JSecondFrame secondFrame = new JSecondFrame();
 
I hope this helps you
 
Best regards,
Filipe Marques
 
--UPDATE--
 
// MyLogin.java
import javax.swing.*;
import java.awt.event.*;
public class MyLogin {
	private JFrame f = new JFrame("Login");
	private JButton bok = new JButton("OK");
	
	public MyLogin() {
	
		f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		f.getContentPane().add(bok);
		
		bok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				f.dispose();
				new SecondFrame();
			}
		});
		f.setSize(100,100);
		f.setVisible(true);
	}
	
	public static void main(String[] args) {
		new MyLogin();
	}
}
 
// SecondFrame.java
import javax.swing.*;
public class SecondFrame {
	private JFrame f = new JFrame("Second");
	
	public SecondFrame() {
	
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setSize(300,300);
		f.setVisible(true);
	}
}
 
The login JFrame is only a button and when you click it, the login window is disposed and the second window appears.
  Permalink  
v2
Comments
Kapilkp at 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 at 22-Mar-13 8:27am
   
Kapilkp, I update my answer with a sample code. It does nothing, it's only to show you. (:
Kapilkp at 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 at 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
0 OriginalGriff 383
1 Richard Deeming 180
2 ChauhanAjay 176
3 Sergey Alexandrovich Kryukov 171
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2014
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