Results 1 to 8 of 8

Thread: JButton help :)

  1. #1
    yasmin k is offline Member
    Join Date
    Mar 2009
    Posts
    23
    Rep Power
    0

    Exclamation JButton help :)

    Hello there

    i am trying to create a hangman game using GUI, but first i a have produced 26 buttons but as i expand the frame, the buttons also expand. how can i fix that?

    thank you for your time :)







    Java Code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*; //for map
    
    public class Hangman {
      public static void main(String[] args) {
       
    	  JFrame frame = new JFrame("Guessing Game");
    		frame.setVisible(true);
    		frame.setSize(400, 400);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		
      
    		JPanel buttons = new JPanel();
    		frame.add(buttons);
    		
    		 buttons.setLayout(new GridLayout(3, 7));
    		 buttons.add(new JButton("A"));
    		 buttons.add(new JButton("B"));
    		 buttons.add(new JButton("C"));  // for empty cell
    		 buttons.add(new JButton("D"));
    		 buttons.add(new JButton("E"));
    		 buttons.add(new JButton("F"));
    		 buttons.add(new JButton("G"));
    		 buttons.add(new JButton("H"));
    		 buttons.add(new JButton("I"));
    		 buttons.add(new JButton("J"));
    		 buttons.add(new JButton("K"));
    		 buttons.add(new JButton("L"));
    		 buttons.add(new JButton("M"));
    		 buttons.add(new JButton("N"));
    		 buttons.add(new JButton("O"));
    		 buttons.add(new JButton("P"));
    		 buttons.add(new JButton("Q"));
    		 buttons.add(new JButton("R"));
    		 buttons.add(new JButton("S"));
    		 buttons.add(new JButton("T"));
    		 buttons.add(new JButton("U"));
    		 buttons.add(new JButton("V"));
    		 buttons.add(new JButton("W"));
    		 buttons.add(new JButton("X"));
    		 buttons.add(new JButton("Y"));
    		 buttons.add(new JButton("Z"));
    
    		
    		
      
      
      }
    
    
    
    
    }

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    Java Code:
    JPanel buttons = new JPanel( new GridLayout(3, 7) );
    buttons.add(....);
    JPanel buttonHolder = new JPanel();
    buttonHolder.add( buttons );
    frame.add( buttonHolder );

  3. #3
    yasmin k is offline Member
    Join Date
    Mar 2009
    Posts
    23
    Rep Power
    0

    Default

    sorry again

    but do i add the JBUTTON because when i do i still get a error.

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

    Default

    Quote Originally Posted by yasmin k View Post
    but do i add the JBUTTON because when i do i still get a error.
    Please tell the details of what is going on now and what your code now looks like. Much luck.

  5. #5
    Join Date
    Mar 2009
    Posts
    34
    Rep Power
    0

    Default

    Dont u use an IDE like Netbeans to develop java applications

  6. #6
    yasmin k is offline Member
    Join Date
    Mar 2009
    Posts
    23
    Rep Power
    0

    Default

    no i'm using eclipse and why not i will have to use it next year for my project.

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

    Default

    Again, the details are important. If you've changed your code, it would be helpful to post that code. If you generate an error or exception, it would be helpful to post the error. I'm not sure how to help given the information at hand. Much luck.

  8. #8
    Aseem is offline Senior Member
    Join Date
    Mar 2009
    Location
    USA
    Posts
    127
    Rep Power
    0

Similar Threads

  1. Jbutton do not show up
    By javaTech in forum AWT / Swing
    Replies: 15
    Last Post: 05-12-2009, 12:22 PM
  2. How to insert a JButton?
    By aRTx in forum New To Java
    Replies: 1
    Last Post: 04-02-2009, 09:43 PM
  3. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 10:48 AM
  4. Help with JButton and layout
    By adlb1300 in forum AWT / Swing
    Replies: 1
    Last Post: 12-25-2007, 08:33 AM
  5. Mouse over JButton
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2007, 09:15 PM

Posting Permissions

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