rena0514 0 Junior Poster in Training
import javax.swing.JFrame;

public class Demographics
{
	public static void main(String[] args)
	{
		JFrame frame= new JFrame("Survey");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		frame.getContentPane().add(new DemographicsPanel());
		
		frame.pack();
		frame.setVisible(true);
	}
}
import java.awt.*;
import javax.swing.*;

public class DemographicsPanel extends JPanel
{
	public  DemographicsPanel()
	{
		this.setLayout (new BorderLayout());
		
		//Panel 1 (North)
		JPanel panel1 = new JPanel();
		panel1.setLayout(new BoxLayout (panel1, BoxLayout.Y_AXIS));
		panel1.setBackground (Color.green);
		JLabel l1= new JLabel("Demographic Survey");
		JLabel l2= new JLabel ("Please complete this form. Press the Submit button when complete.");
		panel1.add(l1);
		panel1.add(l2);
		
		//panel 2 (South)
		JPanel panel2 = new JPanel();
		panel2.setLayout(new BoxLayout (panel2, BoxLayout.X_AXIS));
		panel2.setBackground (Color.green);
		panel2.add(Box.createHorizontalGlue());
		JButton b1 = new JButton ("Clear");
		JButton b2 = new JButton ("Exit");
		panel2.add(b1);
		panel2.add(b2);
		
		//panel 3 (East)
		JPanel panel3 = new JPanel();
		panel3.setLayout(new BoxLayout (panel3, BoxLayout.Y_AXIS));
		panel3.setBackground (Color.yellow);
		JLabel l3 = new JLabel ("Age");
		JSlider ageSlider = new JSlider (JSlider.HORIZONTAL, 0, 100, 0);
		ageSlider.setMajorTickSpacing (50);
		ageSlider.setMinorTickSpacing (10);
		ageSlider.setAlignmentX (Component.LEFT_ALIGNMENT);
		JLabel l4 = new JLabel ("Salary Range:");
		JComboBox salary = new JComboBox();
		salary.setAlignmentX (Component.CENTER_ALIGNMENT);
		panel3.add(l3);
		panel3.add(ageSlider);
		panel3.add(l4);
		panel3.add(salary);
		
		//panel 4-7 (West)
		JPanel panel4 = new JPanel();
		panel4.setLayout(new BoxLayout (panel4, BoxLayout.Y_AXIS));
		panel4.setBackground (Color.yellow);
		JLabel inputLabel = new JLabel ("First Name");
		JTextField fname = new JTextField(10);
		panel4.add(inputLabel);
		panel4.add(fname);
		
		JPanel panel5 = new JPanel();
		panel5.setLayout(new BoxLayout (panel5, BoxLayout.Y_AXIS));
		panel5.setBackground (Color.yellow);
		JLabel inputLabel2 = new JLabel ("Last Name");
		JTextField lname = new JTextField(15);
		panel5.add(inputLabel2);
		panel5.add(lname);
	
		JPanel panel6 = new JPanel();
		panel6.setLayout(new BoxLayout (panel6, BoxLayout.Y_AXIS));
		panel6.setBackground (Color.yellow);
		JLabel inputLabel3 = new JLabel ("Middle Initial");
		JTextField mname = new JTextField(1);
		panel6.add(inputLabel3);
		panel6.add(mname);
		
		JPanel panel7 = new JPanel();
		panel7.setLayout(new BoxLayout (panel7, BoxLayout.X_AXIS));
		panel7.setBackground (Color.yellow);
		JLabel label = new JLabel ("Gender");
		JRadioButton male = new JRadioButton ("Male");
		JRadioButton female=new JRadioButton ("Female");
		panel7.add(label);
		panel7.add(male);
		panel7.add(female);
		
		this.add (panel1, BorderLayout.NORTH);
		this.add (panel2, BorderLayout.SOUTH);
		this.add (panel3, BorderLayout.EAST);
		this.add (panel4, BorderLayout.WEST);
		this.add (panel5, BorderLayout.WEST);
		this.add (panel6, BorderLayout.WEST);
		this.add (panel7, BorderLayout.WEST);
	}
}

teacher wants me to create and interface using border layout...i am having problems with the west part of my layout it is suppose to contain 4 small panels but my 7th panel keeps overrunnig 4 5 and 6

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.