Nested Layout Manager

for Midterm
mail@pastecode.io avatar
unknown
plain_text
a month ago
2.4 kB
5
Indexable
Never
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font;

class Nested_Layout extends JFrame
	{
		private static final int FRAME_WIDTH = 450, FRAME_HEIGHT = 250,
		FRAME_X_ORIGIN = 300, FRAME_Y_ORIGIN = 200;

		private JLabel tlogo,mlogo,hlogo;

		public static void main(String[] args)
		{
				Nested_Layout frame = new Nested_Layout();
				frame.setVisible(true);
		}
		public Nested_Layout()
		{
		JPanel car_panel, brand_panel, price_panel, model_panel, brand_panel1, brand_panel2;
		Container main_panel;

		//set the frame properties
		setSize (FRAME_WIDTH, FRAME_HEIGHT);
		setTitle ("Midterm Laboratory Examination");
		setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);

			main_panel = getContentPane();
			main_panel.setLayout(new GridLayout(2, 2));
			car_panel = new JPanel();
			car_panel.setBorder(BorderFactory.createTitledBorder("Select your car brand: "));

			ImageIcon img_toyo = new ImageIcon("toyota.jpg");
			tlogo = new JLabel(img_toyo);
			tlogo.setBounds(170,10,50,50);
			tlogo.setVisible(true);

			ImageIcon img_mitsu = new ImageIcon("mitsu.jpg");
			mlogo = new JLabel(img_mitsu);
			mlogo.setBounds(170,10,50,50);
			mlogo.setVisible(true);

			ImageIcon img_honda = new ImageIcon("mazda.jpg");
			hlogo = new JLabel(img_honda);
			hlogo.setBounds(170,10,50,50);
			hlogo.setVisible(true);

			brand_panel = new JPanel(new GridLayout(1, 2));
			brand_panel.setBorder(BorderFactory.createTitledBorder(" Car Brands: "));

				brand_panel1 = new JPanel(new BorderLayout());
				brand_panel1.setBorder(BorderFactory.createTitledBorder(" Brand Panel 1: "));

				brand_panel2 = new JPanel(new BorderLayout());
				brand_panel2.setBorder(BorderFactory.createTitledBorder(" Brand Panel 2: "));

			brand_panel.add(brand_panel1);
			brand_panel.add(brand_panel2);

			car_panel.add(tlogo);
			car_panel.add(mlogo);
			car_panel.add(hlogo);

			price_panel = new JPanel(new BorderLayout());
			price_panel.setBorder(BorderFactory.createTitledBorder(" Car Prices: "));

			model_panel = new JPanel(new BorderLayout());
			model_panel.setBorder(BorderFactory.createTitledBorder(" Car Model: "));


			Font f1 = new Font("Bookman Old Style", Font.BOLD, 15);
			main_panel.add(car_panel);
			main_panel.add(brand_panel);
			main_panel.add(price_panel);
			main_panel.add(model_panel);

		}

	}
Leave a Comment