I'm completely stuck on how to organize the layout of this GUI assignment (see:attached picture) I've got the create panel part done, but I can't get anything to work properly for this panel. I've done the code up to the updatePanel method and it compiles but nothing displays. I've tried a few other ways that will display but nowhere close to where they're supposed to be. Any pointers in the right direction would be greatly appreciated.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class SelectPanel extends JPanel
   private Vector petList;
   private JLabel aPLabel, numLabel, numPets;
   private JTextField pField;
   private JTextArea pArea1;
   private JButton button2;
   private JPanel panel1, panel2, panel3, panel4, panel5;

   public SelectPanel(Vector petList)
      this.petList = petList;

	  aPLabel = new JLabel("Available Pet(s)");
	  numLabel = new JLabel("Enter the number of each pet");
	  pField = new JTextField("");
	  pArea1 = new JTextArea("");
	  button2 = new JButton ("Complete my selection(s)");
	  numPets = new JLabel ("You have selected:" +petList.size() + "pet(s)");

	  panel1= new JPanel();
	  panel1.setLayout(new GridLayout(1,2));

	  panel2 = new JPanel();
	  panel2.setLayout(new GridLayout(1,2));

	  panel3 = new JPanel();

	  panel4 = new JPanel(new BorderLayout());
	  panel4.add(panel1, BorderLayout.NORTH);
	  panel4.add(panel2, BorderLayout.CENTER);
	  panel4.add(panel3, BorderLayout.SOUTH);

	  panel5 = new JPanel(new GridLayout(2,1));

     // orgranize components for the panel

 public void updatePanel(String petName)
        //This method can update and refresh the appearance of
        //the select panel by adding the new label with the
        //parameter petName and its textfield

 private class ButtonListener implements ActionListener
       public void actionPerformed(ActionEvent event)
            //When the complete my selection button is pushed,
            //it computes the total number of selected pets and
            //update the label. It should also handle error cases
            //including when a negative number or non-integer value
            //is entered in one of the textfield.
  } //end of ButtonListener class

} //end of SelectPanel class
Member Avatar

Where is your "main"?
Where is your container to hold the panel?