Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 45 of 45

Thread: how can i make a jbutton to close a jframe??

  1. #26
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    i want to close it with an jbutton

  2. #27
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: how can i make a jbutton to close a jframe??

    If you want advice, answer the questions you were asked.
    If you want help, post what you have tried and explain why it is not satisfactory to you.

  3. #28
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    i need help with to make the Jbutton = new Jbutton("EXIT"); i want to make the jbutton to close the jframe when its running so i dont have to click at the top for closing it
    i have tried to add the system.dispose();
    for see if its closing if you click the exit button but i want to make that button close the jframe when its running
    is this more easier for you to understand?

  4. #29
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: how can i make a jbutton to close a jframe??

    The System class does not have a dispose() method. Consult the API for the methods of the class.
    If you are using a different class named System, that is a poorly chosen name for a class, and it should be changed.

  5. #30
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    i found out the solution i added this
    setVisible(false);
    super.dispose();
    in the actionlistener but thanks for helping out

    --- Update ---

    but the last thing i need to find out is how i can open an new jframe with an jbutton while the first jframe is running

    --- Update ---

    but when i click at every button i made it closes automatic at all i just want to make the exit button to close the jframe

    --- Update ---

    how do i make an jbutton to open a new jframe while the first jframe is running

  6. #31
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how can i make a jbutton to open a new jframe?

    how can i makie an jbutton to open a new jframe while the first jframe is running

  7. #32
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: how can i make a jbutton to close a jframe??

    Quote Originally Posted by FastFuture View Post
    i found out the solution i added this
    setVisible(false);
    super.dispose();
    in the actionlistener but thanks for helping out
    Glad you got it working the way you want.


    Quote Originally Posted by FastFuture View Post
    --- Update ---

    [/COLOR]but the last thing i need to find out is how i can open an new jframe with an jbutton while the first jframe is running

    --- Update ---

    how do i make an jbutton to open a new jframe while the first jframe is running
    See post number 19 in this thread for the answer to this question...
    Quote Originally Posted by FastFuture View Post
    --- Update ---

    [/COLOR]but when i click at every button i made it closes automatic at all i just want to make the exit button to close the jframe[COLOR="Silver"]
    It sounds to me like you have a problem filtering your events.

    --- Update ---

    You do not need to start a new thread with the same question.
    Especially in the case that your question was answered in this thread twice.
    Threads merged

  8. #33
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    yup im a newbeginner so im having problem with filtering events

    --- Update ---

    i want to make the jbutton button = new jbutton("Start Spaceball"); to open a new jframe but if i add
    button.addActionListener(this);
    and this.add(button); and when i open the jframe and click start spaceball it closes beacuse i added this under

    @Override
    public void actionPerformed(ActionEvent e) {
    this.setTitle("EXITING");
    setVisible(false);
    super.dispose();

    it closes the start spaceball button beacuse i added the actionlistener to the jbutton and i dont want to let that happen if click it. i want it to open a new jframe while the first one is running thats the problem
    i hope this explains more of that i need help to

  9. #34
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: how can i make a jbutton to close a jframe??

    Use an action command to help filter. If you are using 7 or later you can switch on the String

  10. #35
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    can i make one called addactionlistener(string) ?? can you type the code how to do it im using java 7 in the eclipse

    --- Update ---

    can you write the code ??? so i can see a little more about it?

  11. #36
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how can i make a jbutton to open a new jframe?

    how can i make my start spaceball jbutton to open a new jframe
    with the actionlistener??

  12. #37
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: how can i make a jbutton to close a jframe??

    Please do not create another thread with the same question. This is your third try.
    You can refer to the answer given in post #19. If you do not understand it, ask a question.

  13. #38
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how can i make a jbutton to open a new jframe?

    how can i make an jbutton to open a new jframe while the first one is running i want to create a new window so it openes the game when you click at start game button

  14. #39
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,384
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: how can i make a jbutton to open a new jframe?

    What have you tried? Where are you stuck? Where is your SSCCE?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #40
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,307
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: how can i make a jbutton to close a jframe??

    jps above asked you to stop creating new threads, and yet you do it again. Consider this a warning - do so again and you leave the moderating staff no other choice to take further action. I have merged your threads with this one.

    Given you have yet to follow the advice given, or even elaborate on your problem, I'm not sure what sort of help you expect.

  16. #41
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    omg im a newbeginner i want the freaking JButton button = new JButton("Start Spaceball") i want that button to open a new jframe/window when the first one is running since the first jframe is running with the buttons on and i want to make the button i said to open a new jframe
    i cant do that in actionlistener since it add's det closing at the exit button and if i click spaceball it closes the program since i added button.addActionlistener and that makes the buttons close since i added frame.dispose() under the actionperformed/ActionListener if you dont understand i dont have any more stuff to explain since that is all i need help with

  17. #42
    Junior Member
    Join Date
    May 2013
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    but anyways man i have figured the both solution to get it work now i an jbutton opening a frame and a jbutton closing the frame

  18. #43
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: how can i make a jbutton to close a jframe??

    I am happy you figured it out and got it working.
    Please post the final solution for future readers and mark the thread as solved if all is well

  19. #44
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: how can i make a jbutton to close a jframe??

    You could use frame.setVisible(false); There's probably a 'right' way to actually close it though

  20. #45
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: how can i make a jbutton to close a jframe??

    Quote Originally Posted by Benner View Post
    You could use frame.setVisible(false); There's probably a 'right' way to actually close it though
    Window.setVisible(boolean) will make the window hide or show but not close.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Why can't I close my JFrame ?
    By bartolio in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 20th, 2013, 10:23 AM
  2. Close jframe
    By takamine in forum AWT / Java Swing
    Replies: 4
    Last Post: February 3rd, 2013, 01:16 PM
  3. [SOLVED] Jframe Pop outs when clicking JButton
    By Java Programmer in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 22nd, 2012, 04:09 PM
  4. help with JButton closing a JFrame :)
    By skerridge in forum AWT / Java Swing
    Replies: 15
    Last Post: January 16th, 2012, 12:11 AM
  5. how to make a simple JButton on a JFrame window?
    By chronoz13 in forum AWT / Java Swing
    Replies: 8
    Last Post: November 20th, 2009, 09:08 PM