Solved

gui clean up

Posted on 2004-09-11
5
190 Views
Last Modified: 2010-03-31
Can anyone tell me how to place my gui components on this win form in some sort of order?


package com.softwareConstruction;

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;

public class AssociateApplet extends Applet
   implements ActionListener {
   
    //Variable declarations
    private Frame win;
    private TextField mapInputText, domainInputText;
    private Label domainContent, mapContent;
    private static final String submitInput = "Submit input";
    private static final String bye  = " Exit ";
    private static final String addDomainValue  = " Add Value to Domain ";    
    private HashSet hashSet = new HashSet();
    private HashMap hashMap = new HashMap();
   
   public void actionPerformed ( ActionEvent e) {
      String cmd = e.getActionCommand();
      if ( cmd.equals( submitInput ) ) {
         
          //Use the associate class to add the object and key to the map
      }
      else if ( cmd.equals( addDomainValue ) ) {
          //Add the value to the domain
         
       }
      else if ( cmd.equals( bye ) ) {
         win.setVisible(false);
      }
   }

   public void init() {

      win = new Frame ( "Associative Application" );
     
      //Define a new TextField to handle the map value input
      this.mapInputText = new TextField("", 20);
      this.domainInputText = new TextField("", 20);
     
      //Add the text Field
      win.add(mapInputText);
      win.add(domainInputText);
     
      //Create a new window
      win.setLayout ( new FlowLayout() );
     
      //Add the submitInput and exit buttons to the window
      addButton ( submitInput ); addButton ( bye ); addButton(addDomainValue);
     
      //Add the label for the domain content
      domainContent = new Label( "Domain Content" );
      domainContent.setFont (new Font ( "Dialog", Font.BOLD, 14 ) );
      domainContent.setBackground ( Color.green );
      domainContent.setAlignment ( Label.CENTER );
     
      //Add the window that will show us what is in the domain
      win.add ( domainContent );
     
     
      //Add the label for the domain content
      mapContent = new Label( "Map Content" );
      mapContent.setFont (new Font ( "Dialog", Font.BOLD, 14 ) );
      mapContent.setBackground ( Color.green );
      mapContent.setAlignment ( Label.CENTER );
     
      //Add the window that will show us what is in the domain
      win.add ( mapContent );
     
     
      win.setSize ( 600, 500 );
   }

   public void start() {
         win.setVisible(true);
   }

   public void stop() {
         win.setVisible(false);
   }

   private void addButton ( String name ) {
      Button b = new Button ( name );
      b.setFont (new Font ( "Helvetica", Font.BOLD, 14 ) );
      b.addActionListener ( this );
      win.add ( b );
   }

   private void display(){
       
       
   }

}

0
Comment
Question by:jayrod
5 Comments
 
LVL 3

Assisted Solution

by:aviadbd
aviadbd earned 100 total points
ID: 12033707

The order of your gui components is determined by your LayoutManager. I see you're using the FlowLayout, so just read its docs here: http://java.sun.com/j2se/1.4.2/docs/api/index.html

You can also use a visual editor to place the gui components on your layout. If you use Eclipse (www.eclipse.org) you could use the VE plugin: http://www.eclipse.org/vep/

Good luck!
AviadBD.
0
 
LVL 8

Expert Comment

by:pjcrooks2000
ID: 12034004
Yep Layout managers check them out from the Sun site as aviadbd says :)

pjcrooks2000
0
 
LVL 16

Accepted Solution

by:
suprapto45 earned 400 total points
ID: 12035084
Dear jayrod,

Mmmm....so if I am not mistaken, you want to have some mechanism where you can place your GUI nicely. To do that, as aviadbd and pjcrooks2000 said, yes, you need to use Layout Manager. Let me explain you the concept.

Your win form (the applet that you have created) is a container where it can be divided freely by us. Well, the first easy and default LayoutManager is FlowLayout manager which is actually you used on your applet. LayoutManager has the use to organize your GUI components in the container (either your win form or Panel...we talked Panel later on). If you do not specify any layout manager then it takes FlowLayout as the default layout manager. FlowLayout will alwasy place the components (such as Button, TextField or etc) from the left to the right.

There are many types of LayoutManager such as GridLayout (row and column), BorderLayout (north, east, west and etc) and etc. Now, to create a sophisticated GUI arrangements, you need to have Panel which behaves exactly the same as your container (win form). Each Panel can have its own LayoutManager, it also can store the components such as buttons and etc. Now, what you need to do is to apply your win form with the LayoutManager and place each Panel (contains the GUI components) to your win form.

In below example, I show you how to use BorderLayout to modify your applet. Some components are placed on North, West and South of your win form.

/* Start here */
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.*;

public class MeowTest extends Applet
   implements ActionListener {
   
    //Variable declarations
    private Frame win;
    private Panel panel;
    private Panel panel2;
    private TextField mapInputText, domainInputText;
    private Label domainContent, mapContent;
    private static final String submitInput = "Submit input";
    private static final String bye  = " Exit ";
    private static final String addDomainValue  = " Add Value to Domain ";    
    private HashSet hashSet = new HashSet();
    private HashMap hashMap = new HashMap();
   
   public void actionPerformed ( ActionEvent e) {
      String cmd = e.getActionCommand();
      if ( cmd.equals( submitInput ) ) {
         
          //Use the associate class to add the object and key to the map
      }
      else if ( cmd.equals( addDomainValue ) ) {
          //Add the value to the domain
         
       }
      else if ( cmd.equals( bye ) ) {
         win.setVisible(false);
      }
   }

   public void init() {

      win = new Frame ( "Associative Application" );
      panel = new Panel();
      panel2 = new Panel();

      //Define a new TextField to handle the map value input
      this.mapInputText = new TextField("", 20);
      this.domainInputText = new TextField("", 20);
     
      //Add the text Field
      //win.add(mapInputText);
      //win.add(domainInputText);

      panel2.add (domainInputText);
      panel2.add (mapInputText);

      //Create a new window

      win.setLayout ( new BorderLayout() );
     
      //Add the submitInput and exit buttons to the window
      addButton ( submitInput );
      addButton ( bye );
      addButton(addDomainValue);
     
      win.add (panel, BorderLayout.WEST);
      win.add (panel2, BorderLayout.CENTER);
      //Add the label for the domain content
      domainContent = new Label( "Domain Content" );
      domainContent.setFont (new Font ( "Dialog", Font.BOLD, 14 ) );
      domainContent.setBackground ( Color.green );
      domainContent.setAlignment ( Label.CENTER );
     
      //Add the window that will show us what is in the domain
      win.add ( domainContent , BorderLayout.NORTH);
     
     
      //Add the label for the domain content
      mapContent = new Label( "Map Content" );
      mapContent.setFont (new Font ( "Dialog", Font.BOLD, 14 ) );
      mapContent.setBackground ( Color.green );
      mapContent.setAlignment ( Label.CENTER );
     
      //Add the window that will show us what is in the domain
      win.add ( mapContent , BorderLayout.SOUTH);
     
     
      win.setSize ( 600, 500 );
   }

   public void start() {
         win.setVisible(true);
   }

   public void stop() {
         win.setVisible(false);
   }

   private void addButton ( String name ) {
      Button b = new Button ( name );
      b.setFont (new Font ( "Helvetica", Font.BOLD, 14 ) );
      b.addActionListener ( this );
      panel.add ( b );
   }

   private void display(){
       
       
   }

}

/* End here */
0
 
LVL 3

Author Comment

by:jayrod
ID: 12036818
I've downloaded the vep and i'm using eclipse 3.0 and I can't get the stinking thing to work for me... Once I have it installed.. how do I know it's working? VEP that is?
0
 
LVL 3

Expert Comment

by:aviadbd
ID: 12037082

You should have a new perspective called VE, and you should have new objects under the "New" window (Where you have "Class", "Interface", "Project" etc, you should have GUI items now).

If you don't have those, you probably didn't install it right.

AviadBD.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error trying to install RTMT Win7 5 60
egit plugin on eclipse 8 63
difference of if loops 23 49
iterator/ListIterator approach 17 26
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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