Results 1 to 12 of 12

Thread: JButton

  1. #1
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default JButton

    how do i make a button that changes the window? or moves to another frame?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton

    Quote Originally Posted by Proshitness View Post
    how do i make a button that changes the window? or moves to another frame?
    You'll add an ActionListener to the JButton and inside the listener's actionPerformed method have code that does what you want, be that display another window, perhaps a JDialog, or swap views on the current window via a CardLayout. The details of this code will all depend on how your current application is set up and what you eventually want to do with the new view.

    If you haven't had a look yet, you'll want to check out and study the Swing tutorials which you can find here: Using Swing Components.

    Best of luck!

  3. #3
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: JButton

    just to understand, i have a Menu and i need to create a option menu so do i do that?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton

    Quote Originally Posted by Proshitness View Post
    just to understand, i have a Menu and i need to create a option menu so do i do that?
    Again the tutorials may be able to help you quite a bit. Please check out: How to Use Menus

    As always, if you're still stuck, come on back, and show us what you've tried!
    Again, best of luck!

  5. #5
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: JButton

    how can i make it so that it changes whats inside the main frame, not make a new one?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: JButton

    Quote Originally Posted by Proshitness View Post
    how can i make it so that it changes whats inside the main frame, not make a new one?
    Did you read Fubarable's first response at all?

    Quote Originally Posted by Fubarable View Post
    ... or swap views on the current window via a CardLayout.
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: JButton

    is there a way without the CardLayout? because i cant understand how to use it T.T

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton

    Quote Originally Posted by Proshitness View Post
    is there a way without the CardLayout? because i cant understand how to use it T.T
    Yes, but it's quite a bit more complicated. CardLayout is really the way to go, and the solution to your problem is not to go around it, but to try to understand it. What confuses you about it?

  9. #9
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: JButton

    umm well i look at it, and i dont understand how to use the JPanel, i am used to use JFrame...

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: JButton

    Quote Originally Posted by Proshitness View Post
    umm well i look at it, and i dont understand how to use the JPanel, i am used to use JFrame...
    There's also a tutorial on JPanels which you should read -- it's in the same tutorial library, and I strongly recommend that you study it regardless of whether you use a CardLayout or not, since you'll need an understanding of these components if you're to do any Swing programming.

  11. #11
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: JButton

    ok thanks ^_^

  12. #12
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: JButton

    ok so i made it successfully, but how do i use it to switch between classes? like i have this option class and the main GUI class, how do i change between the panel in one class and the panel on the other class?

Similar Threads

  1. ActionListener for JButton after changing Button to JButton
    By ravi.joshi53 in forum Java Applets
    Replies: 2
    Last Post: 10-07-2011, 07:35 AM
  2. JButton help
    By ThrashingBoy in forum New To Java
    Replies: 8
    Last Post: 03-01-2011, 01:48 AM
  3. Regarding JButton
    By sneha_v27 in forum AWT / Swing
    Replies: 4
    Last Post: 02-18-2011, 02:17 PM
  4. JButton help :)
    By yasmin k in forum AWT / Swing
    Replies: 7
    Last Post: 11-12-2009, 09:53 PM
  5. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 10:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •