We help IT Professionals succeed at work.
Get Started

Line up columns

powerger
powerger asked
on
258 Views
Last Modified: 2010-03-31
I am trying to get this code to line up in 2 columns with the first 2 labels as headers, am i going the right way about it, trying to teach myself Java, having difficulty?  Here is the code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
class AddMember1 extends JFrame{
      
      String dt[] = {"Antrim","Armagh","Carlow","Cavan","Clare","Cork","Derry","Donegal","Down","Dublin","Fermanagh","Galway","Kerry","Kildare","Kilkenny","Laois","Leitrim","Limerick","Longford","Louth","Mayo","Meath","Monaghan","Offaly","Roscommon","Sligo","Tipperary","Tyrone","Waterford","Westmeath","Wexford","Wicklow"};
      String fm[] = {"Male","Female"};            
      String ai[] = {"Active","Inactive"};      
      
      //set up row 1
      JPanel row1 = new JPanel();
      JLabel techno = new JLabel("TECHNOFIT GYM SYSTEM", SwingConstants.CENTER );

      //set up row 2
      JPanel row2 = new JPanel();
      JLabel add = new JLabel("Add Member", SwingConstants.CENTER );
      
      //set up row 3
      JPanel row3 = new JPanel();
      JLabel memberid = new JLabel("Member ID");
      JTextField memberidvalue = new JTextField(10);
      
      //set up row 4
      JPanel row4 = new JPanel();      
      JLabel forename = new JLabel("Forename");
      JTextField forenamevalue = new JTextField(10);
      
      //set up row 5
      JPanel row5 = new JPanel();
      JLabel surname = new JLabel("Surname");
      JTextField surnamevalue = new JTextField(10);
      
      //set up row 6
      JPanel row6 = new JPanel();      
      JLabel address1 = new JLabel("Address 1");
      JTextField address1value = new JTextField(10);
            
      //set up row 7
      JPanel row7 = new JPanel();
      JLabel address2 = new JLabel("Address 2");
      JTextField address2value = new JTextField(10);
      
      //set up row 8
      JPanel row8 = new JPanel();
      JLabel county = new JLabel("County");
      JComboBox combo;
      
      //set up row 9
      JPanel row9 = new JPanel();
      JLabel height = new JLabel("Height");
      JTextField heightvalue = new JTextField(10);
      
      //set up row 10
      JPanel row10 = new JPanel();      
      JLabel teleno = new JLabel("Telephone No");
      JTextField telenovalue = new JTextField(10);      
      
      //set up row 11
      JPanel row11 = new JPanel();      
      JLabel dob = new JLabel("DOB");
      JTextField dobvalue = new JTextField(10);
      
      //set up row 12
      JPanel row12 = new JPanel();            
      JLabel gender = new JLabel("Gender");
      JComboBox combo1;

      //set up row 13
      JPanel row13 = new JPanel();
      JLabel dateadded = new JLabel("Date Added");
      JTextField dateaddedvalue = new JTextField(10);
            
      //set up row 14
      JPanel row14 = new JPanel();
      JLabel expirydate = new JLabel("Expiry Date");
      JTextField expirydatevalue = new JTextField(10);      
      
      //set up row 15
      JPanel row15 = new JPanel();      
      JLabel status = new JLabel("Status");
      JComboBox combo2;
      
      //set up row 16
      JPanel row16 = new JPanel();
      private JButton b1;
      

public AddMember1()
      {
            
            super("Add Member");
            setSize(500, 550);
            GridLayout layout = new GridLayout(8,2);
            b1 = new JButton("OK");
            Container c = getContentPane();
            c.setLayout(new FlowLayout());
            
            FlowLayout layout1 = new FlowLayout(FlowLayout.LEFT, 10, 10 );
            row1.setLayout(layout1);
            row1.add(techno);
            c.add(row1);
      
            FlowLayout layout2 = new FlowLayout(FlowLayout.LEFT, 10, 10 );
            row2.setLayout(layout2);
            row2.add(add);
            c.add(row2);


            FlowLayout layout3 = new FlowLayout(FlowLayout.LEFT);
            row3.setLayout(layout3);
            row3.add(memberid);
            row3.add(memberidvalue);
            c.add(row3);


            FlowLayout layout4 = new FlowLayout(FlowLayout.LEFT);
            row4.setLayout(layout4);
            row4.add(forename);
            row4.add(forenamevalue);
            c.add(row4);

            FlowLayout layout5 = new FlowLayout(FlowLayout.LEFT);
            row5.setLayout(layout5);
            row5.add(surname);
            row5.add(surnamevalue);
            c.add(row5);

            FlowLayout layout6 = new FlowLayout(FlowLayout.LEFT);
            row6.setLayout(layout6);
            row6.add(address1);
            row6.add(address1value);
            c.add(row6);

            FlowLayout layout7 = new FlowLayout(FlowLayout.LEFT);
            row7.setLayout(layout7);
            row7.add(address2);
            row7.add(address2value);
            c.add(row7);


            FlowLayout layout8 = new FlowLayout(FlowLayout.LEFT);
            row8.setLayout(layout8);
            combo = new JComboBox(dt);
            combo.setMaximumRowCount(5);
            row8.add(county);
            row8.add(combo);
            c.add(row8);

            FlowLayout layout9 = new FlowLayout(FlowLayout.LEFT);
            row9.setLayout(layout9);
            row9.add(height);
            row9.add(heightvalue);
            c.add(row9);

            FlowLayout layout10 = new FlowLayout(FlowLayout.LEFT);
            row10.setLayout(layout10);
            row10.add(teleno);
            row10.add(telenovalue);
            c.add(row10);

            FlowLayout layout11 = new FlowLayout(FlowLayout.LEFT);
            row11.setLayout(layout11);
            row11.add(dob);
            row11.add(dobvalue);
            c.add(row11);

            FlowLayout layout12 = new FlowLayout(FlowLayout.LEFT);
            row12.setLayout(layout12);
            combo1 = new JComboBox(fm);
            combo.setMaximumRowCount(1);
            row12.add(gender);
            row12.add(combo1);
            c.add(row12);

            FlowLayout layout13 = new FlowLayout(FlowLayout.LEFT);
            row13.setLayout(layout13);
            row13.add(dateadded);
            row13.add(dateaddedvalue);
            c.add(row13);

            FlowLayout layout14 = new FlowLayout(FlowLayout.LEFT);
            row14.setLayout(layout14);
            row14.add(expirydate);
            row14.add(expirydatevalue);
            c.add(row14);

            
            FlowLayout layout15 = new FlowLayout(FlowLayout.LEFT);
            row15.setLayout(layout15);
            combo2 = new JComboBox(ai);
            combo.setMaximumRowCount(1);
            row15.add(status);
            row15.add(combo2);
            c.add(row15);

            
            FlowLayout layout16 = new FlowLayout(FlowLayout.LEFT);
            row16.setLayout(layout16);
            row16.add(b1);
            c.add(row16);
            
            memberidvalue.requestFocus();
            //add button actionlistener
            
            b1.addActionListener(new ButtonListenerB1());

            addWindowListener(new WindowAdapter(){
                  public void windowClosing(WindowEvent e){
                        dispose();

                  }
            });
      }


      class ButtonListenerB1 implements ActionListener
      {
            public void actionPerformed(ActionEvent e)
            {
                  System.out.println(memberidvalue.getText());
                  System.out.println(forenamevalue.getText());
                  System.out.println(surnamevalue.getText());
                  System.out.println(address1value.getText());
                  System.out.println(address2value.getText());
                  System.out.println(heightvalue.getText());
                  System.out.println(telenovalue.getText());
                  System.out.println(dobvalue.getText());      
                  System.out.println(dateaddedvalue.getText());
                  System.out.println(expirydatevalue.getText());
                  System.out.println(combo.getSelectedItem());
                  System.out.println(combo1.getSelectedItem());
                  System.out.println(combo2.getSelectedItem());
            }
      
}

      public static void main(String[] args)
      {
            AddMember1 memb = new AddMember1();
            memb.setLocation(100,100);
            memb.setVisible(true);
      }
}
Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE