Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

gui clean up

Posted on 2004-09-11
5
Medium Priority
?
196 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
[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
5 Comments
 
LVL 3

Assisted Solution

by:aviadbd
aviadbd earned 400 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 1600 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

609 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