Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How JFrame close another JFrame?

 
Ranch Hand
Posts: 302
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have an JFrame for login, after make login the new JFrame class  is loaded fine. The JFrame that is loaded have many JInternalFrame that work without problem. My problem is that I can't close the Login Jframe. How I close my JFrame Login?
Below my Login class.

And here the JFrame that is called by Login.

Thanks.
 
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cezar Apulchro wrote:How I close my JFrame Login?



Most likely, calling its dispose() method will do the trick.

Of course, you have to have a reference to that JFrame to call any of its methods. I don't know if you have that or not, there was far too much code for anybody to go through all of it and find out. So if the question still exists for you, I would suggest writing an SSCCE in which you remove all of the code which doesn't involve closing the other frame. That would be much easier to deal with.
 
Marshal
Posts: 72478
315
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would also ask why you want multiple frames. You might do better to show one of the displays as a dialogue window.
 
Cezar Apulchro
Ranch Hand
Posts: 302
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, after enter login and my condition be accepted my page PageUsuario is loaded fine but the dispose don't doing.

Where I'm wrong.
 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can see that the code you posted calls the dispose() method on something. Must be a JFrame, I suppose. So it would help if you told us what happens.

Is there more than one frame visible when that method is called? Does one of them disappear? Is it the wrong one?

Or is there some other problem? (I notice that line 25 in that code could be deleted, since it doesn't do anything useful -- unless creating a new PageUsuario object has some side effects.)
 
Cezar Apulchro
Ranch Hand
Posts: 302
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, the line 25 is to execute another JFrame to make other things like record new user in my db tables and so on, line 25 are ok. After execute line 25 both frame is visible my Login frame and the PageUsuario loaded by line 25 that is correct. What I want is to close the Login frame by method dispose in line 27.
 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why you don't just use a JOptionPane to ask for login information. But anyway here's my code which disposes one JFrame and displays another one:



Try it on your machine and see if it works for you.
 
Campbell Ritchie
Marshal
Posts: 72478
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:. . . use a JOptionPane to ask for login information.  . . .

Agree: one app, one JFrame.
 
Saloon Keeper
Posts: 12825
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Going by the other questions Cezar has posted, it is very likely that dispose() is called on the wrong JFrame reference.

Cezar, you've been advised multiple times not to extend JFrame. Why are you ignoring this advise? Why don't you use an instance field to hold the reference to the frame?
 
Cezar Apulchro
Ranch Hand
Posts: 302
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, sorry by delay. I don't understand the last contact. What is " instance field to hold the reference to the frame?". How define this. About your code example I get the Name and PassWord to locate in my DB table and get the column tipo, the column tipo show me  what JFrame I must to open.
 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Your variable "fPageMed" is the instance variable you should be using. It sounds like you have already been told not to extend JFrame. Doing that just leads to confusion -- is your JFrame referred to as "this" or as "fPageMed"? So don't extend JFrame. Like so:

 
Cezar Apulchro
Ranch Hand
Posts: 302
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I solved my problem.
This is where are my problem.

Then I changed this method to:

And:

Thanks and best regards.
 
This will take every ounce of my mental strength! All for a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic