• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code to generate a Grid Test GUI

 
Mike Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am completely at a loss for this and need an answer asap.
I need to know the code to generate a GUI with the number from 1 to 12 with each number in a seperate section.
And if anyone knows how to cod the numbers 1 to 4 in a pannel i would be greatly apricative.
I need this info very badly and very quickly i do not know where to look and i need the code to generate this. Any help on either of these topics and you would be a life saver
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

Have you worked with Swing GUI programs at all? Here's a Sun tutorial to get you going: http://java.sun.com/docs/books/tutorial/uiswing/ You might be looking for a GridBagLayout once you're comforatable with making GUI programs.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First, let me point out our policy on display names which requires that you use a real-sounding first and last name. Single names and "handles" aren't acceptable. You can change your display name here. THanks for your immediate attention.

Second: we've got a forum for Swing and AWT questions like yours; I'm going to move this post as well as your "advanced" one to that forum where they will be on-topic.
 
Mike Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Name changed and thank you.
I know that it is a big ask but if anyone could supply me with code as i am short of time i would be greatfull.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
start by creating a JFrame
create a JPanel
set the JPanel's layout manager to a GridLayout(ROWS,COLUMNS)
in a for loop (where x = 0; x < ROWS*COLUMNS)
{
create a JLabel
set the JLabel's text to x (or x+1, if 1-based)
add the JLabel to the JPanel
}
add the JPanel to the JFrame
JFrame.pack()
JFrame.setVisible(true)

should just about do it.
if you run into problems, Stan's link earlier will have all the answers
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!