blog




  • Essay / Layout Design - 773

    Deciding Layouts Deciding the layout is a very important step in Java GUI programming, just like solving an algorithm in normal programming. The layout decides how components such as labels, buttons, text fields, etc. are displayed. will be displayed on a frame or window. Some GUIs can be designed using a single panel with a single, simple layout. Some GUIs need to be broken down into smaller panels that need to be added to an external panel. Each smaller panel can have its own layout. The simplest layout is the flow layout. Laying out the stream produces output as a single line. So go for the flow layout if you only have 3 components or less or if you want all the components to be on a single line. Next comes the grid layout. As long as you can figure out the rows and columns, you can use this layout. It is possible to use the grid layout for most applications that you want to develop with a single panel. You can always use filler labels to fill empty spaces. So the grid layout works well in such cases. But if you want to have a very neat GUI with a very good layout, you should go for more than one panel. In this case, the grid, flow and border are all used together. Developing a GUI depends on the type of problem. There are 2 types of GUI problems:1. Problems that simply state that you need to do certain things. In this case, the layout of the GUI is entirely in your hands.2. Issues where you are given a preview of what the GUI will look like. Type 1: In case 1, you need to start with paper and pencil. - Read the problem and identify what should be displayed to the user - Based on this, draw a simple diagram of how you want your GUI to look like. Next, start deciding on the layout. For example, consider the problem below: Write a GUI Java program that takes 2 numbers from the user, adds them and displays the sum. Solution: 1. For this you need 2 text fields to read 2 entries. 2 labels to indicate what to enter in the text fields.2. 1 button to start the calculation.3. 1 text field to display the result and 1 label to address the text field.4. The approximate diagram will be5. For the diagram above, if you are going to use a single panel, the grid layout is the best choice. To decide on the layout, dissect the diagram as shown below.