Java prog#8. How to close previous jframe on the opening of new jframe in netbeans

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • it's simple just follow the below code:
    First import these two files below
    import java.awt.event.*;
    import java.awt.*;
    then write the method for close
    public void close(){
    WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
    }
    ★★★Top Online Courses From ProgrammingKnowledge ★★★
    Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
    Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
    Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
    Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
    C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
    C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
    PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
    Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
    C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
    JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
    NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
    Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
    Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
    Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
    MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
    QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
    ★★★ Online Courses to learn ★★★
    Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqc...
    Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
    Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
    Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
    MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
    DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
    Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
    AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
    Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
    Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
    Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
    Kotlin Android Development Masterclass - bit.ly/2GcblsI
    Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
    ★★★ Follow ★★★
    My Website - www.codebind.com
    DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
    ------------------------------------------------------------------------
    Java: How do I close a JFrame while opening another one?
    How to close a jframe without closing the main program
    Close one JFrame without closing another?
    passing data from one jframe to another
    How to disable main JFrame when open new JFrame
    Opening new JFrame replaces current window
    NetBeans Forums - Opening new Jframe in existing window
    iit Learn java netbeans
    java tutorial netbeans

КОМЕНТАРІ • 114

  • @luigimarideleon6093
    @luigimarideleon6093 8 років тому

    'Thanks men! Been solving this from night to morning, then I found this video. Noob here by the way so I'm so glad I found this. Thank you.

  • @ridaayubch2814
    @ridaayubch2814 7 років тому +2

    very helpful, every word of you was clear and every step is slow and clear that we can follow step by step
    may ALLAH bless you

  • @pinkicito0w
    @pinkicito0w 11 років тому

    i think i learn more watching your videon than at school jajaja thnks for your tutorials my friend, regards from mexico :)

  • @brandomarebole329
    @brandomarebole329 5 років тому

    This video just helped me take a MAJOR step in getting my Computer Science degree. Thank to so much, bro! JUST what I needed.

  • @raip0d
    @raip0d 3 роки тому

    You're the true king

  • @lishaneticha8663
    @lishaneticha8663 9 років тому

    Tnxs Baddy you just solved the biggest problem I was facing!!!

  • @Hydraxon3200
    @Hydraxon3200 12 років тому +1

    nice work, waiting for the next video ;)

  • @Sanjay54251
    @Sanjay54251 8 років тому +2

    we can also put cammand dispose(); insted of window.closing

  • @jerry04SAVED
    @jerry04SAVED 12 років тому

    Hello friend, excuse the trouble first of all these video tutorials are helpful. As you can disable the close button of the window JFrame. In this video the Close method to close the JFrame not be disabled when you disable the close button of the window.
    Greetings Friends ...

  • @channsothun9431
    @channsothun9431 10 років тому +1

    I normally use hide method to close a frame, but I think it is not the right way to actually close a frame because that frame is just invisible but not actually close. Any better idea?

  • @mtxx80
    @mtxx80 8 років тому +32

    I think better and easier would be:
    public void close() {
    this.setVisible(false);
    this.dispose();
    }

    • @aryastark1833
      @aryastark1833 7 років тому +1

      dispose doesnt work when you have a static class

    • @serahganjawala
      @serahganjawala 7 років тому +1

      thanks
      i used this and it worked

    • @javadeveloper-o5j
      @javadeveloper-o5j 7 років тому +1

      Thanks. It really woks.

    • @faizrasulanwar8458
      @faizrasulanwar8458 7 років тому +1

      Jacek Dąbek Its also work for me

    • @Aestridd
      @Aestridd 7 років тому +1

      thanks bro it's actually easier to handle this way

  • @justintheoreo
    @justintheoreo 6 років тому

    Mine is saying, cannot fins symbol, and it is pointing to the Toolkit.getDefaultToolkit line. Any ideas?

  • @amalpfranglin
    @amalpfranglin 2 роки тому

    Thank you. It was very helpful :)

  • @ProgrammingKnowledge
    @ProgrammingKnowledge  12 років тому

    hi thanks for showing me easier code for opening a new jForm I also made a video for that so everybody can learn that and I mansion ur name in the video no 37..........

  • @Swiftkillah1300
    @Swiftkillah1300 12 років тому

    this videos helped me with the first form but more the second form links to a third form then this same function closes everything. How do you make it work when there are more than 2 levels of forms?

  • @waqarjamali
    @waqarjamali 7 років тому +2

    use f.hide(); inside the action of the login

  • @joeyczo5008
    @joeyczo5008 3 роки тому +1

    Thank you !!!

  • @AboMSGL
    @AboMSGL 8 років тому

    Thank yoy,
    You should be attention to change the state of fram in the runtime also

  • @WaleedMdAlHasanOmer
    @WaleedMdAlHasanOmer 10 років тому +1

    Dear
    This code instead of closing the current window, it closes the whole application.
    I used instead this line:
    this.setVisible(false);

  • @Mhtwy
    @Mhtwy 12 років тому

    You. Are. Awesome! Thank you very much that helped alot.

  • @kanananonim3132
    @kanananonim3132 11 років тому

    How to not closing main jframe when closing new. I mean that, when we run the program, there is a button on that jframe, when I click that button new jframe will open, and when I close this new jframe the old one also will be closed. but my wish is that not closing the old jframe until I close it myself.

  • @V_Bhatia
    @V_Bhatia Рік тому

    Thank you very much ❤❤

  • @shell3371
    @shell3371 Рік тому

    Thank you so much!

  • @jimleoromines8114
    @jimleoromines8114 8 років тому +1

    How about InternalFrame ?

  • @luisfernandofragosocarranz1526
    @luisfernandofragosocarranz1526 3 роки тому

    ur great dude :)

  • @ProgrammingKnowledge
    @ProgrammingKnowledge  8 років тому +1

    Click link to Download Source code - www.codebind.com/java-tutorials/whole-java-netbeans-gui-project-source-code/

  • @omkomawar
    @omkomawar 11 років тому

    Thanks it did Helped me....!!!

  • @toeksh
    @toeksh 11 років тому

    how to go back to main jframe after hiding it and moved to another frame
    for example
    mainframe.setvisible(false);
    goto"second frame";
    how to set mainframe to true visible via a back button in the second frame

  • @sriramkuwaitful
    @sriramkuwaitful 8 років тому

    I got it but still the same thing
    i am not getting the previous window closed at all.

  • @charlesndlovu6350
    @charlesndlovu6350 8 років тому

    how about the code for moving from one panel to another pls

  • @hamzasiddiq8179
    @hamzasiddiq8179 4 роки тому

    Thnk you so so much thnka man

  • @dekbd2
    @dekbd2 11 років тому

    can use in Eclipse ?

  • @kenhgiaitriviet9013
    @kenhgiaitriviet9013 10 років тому

    you can do it with dispose method!

  • @Lusches77
    @Lusches77 11 років тому

    what programm do you use ?

  • @philipakpan5898
    @philipakpan5898 8 років тому

    Thanks. Quite useful.

  • @putri4957
    @putri4957 5 років тому

    Thank you! You solved my error!

  • @fernandohood5542
    @fernandohood5542 4 роки тому

    Some smart people have a tendency to over complicate things Ahmed.

  • @nitishkumar-zh2wx
    @nitishkumar-zh2wx 5 років тому

    very helpful
    thanks a lot....

  • @iondhai6074
    @iondhai6074 4 роки тому

    mantap pak abu

  • @natasuah
    @natasuah 11 років тому

    I tried but is not working. I have imported 'import java.awt.event.WindowEvent;'. This is what i have in my method. " public void close(){
    WindowEvent winClosingEvent=new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
    ToolKit.getDefaultToolKit().getSystemEventQueue().postEvent(winClosingEvent);

    }"
    Is complaining of no suitable constructor found for windows Event.
    Could you help me? Thank you

  • @anamikaahmed4887
    @anamikaahmed4887 7 років тому +1

    simply use this.dispose() on the method of the button.
    You don't have to write this much code.

    • @RenXenpai
      @RenXenpai Рік тому

      Lol you saved me thank you

  • @natasuah
    @natasuah 11 років тому

    Yeah I have. I only use dispose() . Hey thanks

  • @faizrasulanwar8458
    @faizrasulanwar8458 7 років тому

    Helpful (:
    Thank you man

  • @MonoarBinahmed
    @MonoarBinahmed 6 років тому

    but Employeeid name surname age????? this form ??

  • @srishtigupta361
    @srishtigupta361 7 років тому

    Helpful tutorials

  • @zahidshabbir2499
    @zahidshabbir2499 10 років тому

    we can also use : this hide();
    It also work too but i am not sure it just hide it or close it too
    does someone know that???

  • @razoR2k
    @razoR2k 12 років тому +1

    this.close();
    close it's already defined in java

  • @niranjanchakankar4428
    @niranjanchakankar4428 8 років тому

    thanks and great post...

  • @ruzainiamer1032
    @ruzainiamer1032 8 років тому +2

    Can you please move the cursor when you're explaining on something in the next video. I can't read. haha. I noticed that on most of your videos.

  • @RecoverIman01
    @RecoverIman01 3 роки тому

    Thanks

  • @MehdiBouzidi
    @MehdiBouzidi 10 років тому

    Thank you verry Much

  • @TheErdemgencoglu
    @TheErdemgencoglu 10 років тому

    Thanks this video bro :)

  • @khaledsale7
    @khaledsale7 9 років тому

    u can just type
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    in the contructer :D

  • @goralAdrian
    @goralAdrian 6 років тому

    Thanks mate.

  • @sriramkuwaitful
    @sriramkuwaitful 8 років тому

    what is .WINDOW_CLOS­ING);??? i am not getting it

    • @sureshnaame6982
      @sureshnaame6982 7 років тому

      It is a DATA_MEMBER, which comes under class WindowEvent.

  • @fathiafraznaaz-zahra1453
    @fathiafraznaaz-zahra1453 9 років тому

    thank you! very useful >O

  • @mukulbadhan5336
    @mukulbadhan5336 11 років тому

    how to close previous window when using framename.main(argv);

  • @riadfaical
    @riadfaical 11 років тому

    ty bro !!

  • @lifeoftomi_
    @lifeoftomi_ 9 років тому

    If you use eclipse,in your actionPerformed method all you need to write is yourFrameName.hide(); so for me that was frmLogin.hide();

    • @lifeoftomi_
      @lifeoftomi_ 9 років тому

      Seeker but if your class already extends JFrame, you should be able to call hide(); or use this.hide(); still in the actionPerformed method and before initialising the new frame.

  • @lu1sner193
    @lu1sner193 11 років тому

    Thanks Bro !

  • @trunghieunguyen7153
    @trunghieunguyen7153 8 років тому

    thank u so much !!!

  • @manishpaul_
    @manishpaul_ 7 років тому

    or just add "dispose();" before opening another frame.

  • @Bluemangrup
    @Bluemangrup 8 років тому

    I did the public void close exactly like the video:
    public void close(){
    WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(WinClosingEvent);
    }
    But it says it can't find symbol: class WindowEvent
    Can someone please explain why?

    • @sureshnaame6982
      @sureshnaame6982 7 років тому +1

      write package "import java.awt.*;" & "import java.awt.event.*;". Because WindowEvent comes under these packages.

    • @waqarjamali
      @waqarjamali 7 років тому +1

      use this.hide();

    • @Bluemangrup
      @Bluemangrup 7 років тому

      Thank you!

  • @riskinovasaputra4018
    @riskinovasaputra4018 8 років тому

    Thank you

  • @crisalide98
    @crisalide98 8 років тому

    Thanks!!!

  • @markjason2
    @markjason2 9 років тому +4

    Or you can use
    ThisFrame.Dispose();
    :D

    • @sanskarsingh9538
      @sanskarsingh9538 6 років тому

      haha i wonder why a person who already knows would be here. thanks though

    • @joanasflute
      @joanasflute 5 років тому

      YOU ARE AN ANGEL

  • @SuperAlphabetagama
    @SuperAlphabetagama 11 років тому

    Why not just use this.setVisible(false);

  • @harveybarcelona7252
    @harveybarcelona7252 7 років тому

    is there another method to close only a frame because your method is too long :V

  • @loooooooooool77
    @loooooooooool77 11 років тому

    didnt work :/

  • @kanananonim3132
    @kanananonim3132 11 років тому

    How to connect with you? do you have facebook, skype or any?

  • @deepakkumar-pk4kt
    @deepakkumar-pk4kt 9 років тому

    thanks,...

  • @Shadrech
    @Shadrech 11 років тому

    Don't put it in the public frame() {... } constructor. Put it outside and it will work:
    e.g.
    public class MainFrame extends JFrame {
    public MainFrame() {
    ....
    }
    public void closeFrame() {
    WindowEvent winClosingEvent =......
    }
    }
    Being u asked this 3 months ago I'm probably wasting time answering..u must hav found the solution in these 3 months?...

  • @feero9680
    @feero9680 3 роки тому

    7:00

  • @lighttech7750
    @lighttech7750 5 років тому

    verty esay methode tankes

  • @XC3rocks
    @XC3rocks 8 років тому +2

    it closes out both windows

    • @bbd9106
      @bbd9106 6 років тому

      just set the first frame property to dispose after this process shown in video

  • @EMINEMisnr1
    @EMINEMisnr1 11 років тому

    the easiest would be this.setVisible(false);

  • @Nousa460
    @Nousa460 11 років тому

    :) God bless you (y)

  • @jeanrodrigues6249
    @jeanrodrigues6249 2 роки тому

    Whatsup

  • @fifatemple4781
    @fifatemple4781 5 років тому +1

    Pls stop being annoying my big brain cannot follow ur methodolgical proceedings with the Java Graphical User Interface code so pls halp and extand my mind

  • @Hydraxon3200
    @Hydraxon3200 12 років тому

    btw. it is easier to just write dispose(); before the code for opening a new jForm...for example dispose ();
    new jForm().setVisible(true);
    xD
    ;)

  • @Tomahoop
    @Tomahoop 6 років тому

    at Login.java (or whatever you named it):
    if(rs.next()){
    JOptionPane.showMessageDialog(null, "Username and Password is correct");
    rs.close();
    pst.close();
    patient_info s = new patient_info();
    s.setVisible(true);
    this.dispose(); //use this line of code which makes this entire video pointless
    }

  • @jeanrodrigues6249
    @jeanrodrigues6249 2 роки тому

    Whatsapp

  • @abhishekjilla6782
    @abhishekjilla6782 9 років тому +1

    thanx

  • @kanananonim3132
    @kanananonim3132 11 років тому

    How to connect with you? do you have facebook, skype or any?

  • @ridhokurniawan8899
    @ridhokurniawan8899 10 років тому

    Thanks

  • @winlenglean4224
    @winlenglean4224 8 років тому

    thanks