Results 1 to 8 of 8
Thread: JButton help :)
- 11-05-2009, 05:23 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 23
- Rep Power
- 0
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")); } }
- 11-05-2009, 05:32 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Java Code:JPanel buttons = new JPanel( new GridLayout(3, 7) ); buttons.add(....); JPanel buttonHolder = new JPanel(); buttonHolder.add( buttons ); frame.add( buttonHolder );
- 11-05-2009, 06:14 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 23
- Rep Power
- 0
sorry again
but do i add the JBUTTON because when i do i still get a error.
-
- 11-06-2009, 06:43 AM #5
Dont u use an IDE like Netbeans to develop java applications
- 11-07-2009, 12:15 AM #6
Member
- Join Date
- Mar 2009
- Posts
- 23
- Rep Power
- 0
no i'm using eclipse and why not i will have to use it next year for my project.
-
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.
- 11-12-2009, 09:53 PM #8
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
Similar Threads
-
Jbutton do not show up
By javaTech in forum AWT / SwingReplies: 15Last Post: 05-12-2009, 12:22 PM -
How to insert a JButton?
By aRTx in forum New To JavaReplies: 1Last Post: 04-02-2009, 09:43 PM -
Help with JButton
By geoffreybarwise in forum New To JavaReplies: 4Last Post: 05-21-2008, 10:48 AM -
Help with JButton and layout
By adlb1300 in forum AWT / SwingReplies: 1Last Post: 12-25-2007, 08:33 AM -
Mouse over JButton
By sandor in forum AWT / SwingReplies: 1Last Post: 05-17-2007, 09:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks