?
Solved

Help with GUI coding!

Posted on 2003-03-23
6
Medium Priority
?
196 Views
Last Modified: 2010-03-31
Hi,
I've made up code to guess random numbers from 3 text fields. One thing that has been worrying me is the size of the constructor the GUI is within. Is there any way to break up a constructor when using JPanel's and JTabbedPane's(Perhaps making it modular). Can anyone give me a url or any advise?
0
Comment
Question by:edgrey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Accepted Solution

by:
Wysiwyg earned 152 total points
ID: 8190373
I always use a jbInit() method to do all the gui work.
Something like

public class foo extends JFrame //JDialog ?
{
  GridBagLayout gbl = new GridBagLayout();
  JPanel infoPanel = new JPanel();
  JPanel buttonPanel = new JPanel();
 
  JLabel nameLabel = new JLabel();
  JButton ok = new JButton();

  public foo()
  {
    jbInit();
  }

  protected void jbInit()
  {
    JPanel contentPanel = (JPanel)this.getContentPane();
    //...
    infoPanel.add(nameLabel);
    //...
    buttonPanel.add(ok);
    //...
    contentPanel.setLayout(gbl);
    contentPanel.add(infoPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 10, 5, 10), 0, 0));
   
    contentPanel.add(buttonPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 10, 5, 10), 0, 0));
  }
  //...
}
0
 
LVL 2

Assisted Solution

by:bkrahmer
bkrahmer earned 148 total points
ID: 8192750
I have great respect for functions which are short, but I think 1 line is arbitrarily too short.  There is no point in that.  I think that all functions should fit on your screen and (ideally) do only one thing.  The best answer I think is to break down the problem.  You could try something like this:

public myConstructor
{
  createLayoutManagers();
  createPanels();
  createDrawingPanel();
  setupWindowOptions();
  ..//blah blah blah
}

I think this will make it much easier to read.

brian
0
 

Expert Comment

by:CleanupPing
ID: 9058532
edgrey:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9730819
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept bkrahmer's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9730830
Correction - Points to be split between Wysiwig and bkrahmer.

Sorry Wysiwig, I initially missed your comment.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question