This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How JFrame close another JFrame?

 
Ranch Hand
Posts: 193
2
  • Mark post as helpful
  • send pies
  • 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: 25927
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 70598
287
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 193
2
  • Mark post as helpful
  • send pies
  • 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: 25927
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 193
2
  • Mark post as helpful
  • send pies
  • 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: 25927
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 70598
287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Agree: one app, one JFrame.
 
Saloon Keeper
Posts: 12402
269
  • Mark post as helpful
  • send pies
  • 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: 193
2
  • Mark post as helpful
  • send pies
  • 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: 25927
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 193
2
  • Mark post as helpful
  • send pies
  • 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.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic