Java / Other Minor Java Work / EF_UsedCarApp.java
EF_UsedCarApp.java
Raw
 /**
  * Program Name: EF_UsedCarApp.java
  * Author: Essam Fahmy
  * Date: Jul 15, 2022
  * Purpose: A GUI for a used car app    
  */

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

public class EF_UsedCarApp extends JFrame
{
	//Declaring Required Variables
	
	private JPanel textPanel, enginePanel, optionsPanel;
	private JRadioButton gasBtn, dieselBtn, hybridBtn, electricBtn;
	private ButtonGroup btnGroup;
	private JCheckBox airChkbx, windowsChkbx, transmissionChkbx;
	private JLabel header1, header2, header3;
	private JButton submitBtn;
	
	public EF_UsedCarApp()
	{
		
		//Setting required properties
		
		super("Essam");

		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(600, 200);
		this.setLocationRelativeTo(null);
		this.setLayout(new GridLayout(1, 3, 5, 5));
		
		//Calling methods and adding panels
		
		textPanelBuild();
		
		this.add(textPanel);
		
		engineTypeBuild();
		
		this.add(enginePanel);
		
		optionsBuild();
		
		this.add(optionsPanel);
		
		this.setVisible(true); 
	}

	
	//Method for building the text fields
	
	public void textPanelBuild()
	{
		JTextField make, model, year;
		
		textPanel = new JPanel();
		
		header1 = new JLabel("Car Search Criteria");
		
		make = new JTextField("Make");
		model = new JTextField("Model");
		year = new JTextField("Year");
		
		textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
		
		textPanel.add(header1);
		textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		textPanel.add(make);
		textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		textPanel.add(model);
		textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		textPanel.add(year);
		
	}
	
	//Method for building the engine type selection menu
	
	public void engineTypeBuild()
	{
		
		enginePanel = new JPanel();
		
		enginePanel.setLayout(new BoxLayout(enginePanel, BoxLayout.Y_AXIS));
		
		header2 = new JLabel("Engine Type");
		enginePanel.add(header2);
		
		enginePanel.add(Box.createRigidArea(new Dimension(0, 10)));
		
		gasBtn = new JRadioButton("Gasoline", true); 
		enginePanel.add(gasBtn);
		
		enginePanel.add(Box.createRigidArea(new Dimension(0, 10)));
		
		dieselBtn = new JRadioButton("Diesel", false); 
		enginePanel.add(dieselBtn);

		enginePanel.add(Box.createRigidArea(new Dimension(0, 10)));
		
		hybridBtn = new JRadioButton("Hybrid", false); 
		enginePanel.add(hybridBtn);
		
		enginePanel.add(Box.createRigidArea(new Dimension(0, 10)));

		electricBtn = new JRadioButton("Electric", false);  
		enginePanel.add(electricBtn);

		btnGroup = new ButtonGroup();
		
		btnGroup.add(gasBtn);
		btnGroup.add(dieselBtn);
		btnGroup.add(hybridBtn);
		btnGroup.add(electricBtn);
		
		
	}
	
	//Method for building the options and submit button
	
	public void optionsBuild()
	{
		
		optionsPanel = new JPanel();
		optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
		header3 = new JLabel("Options");
		airChkbx = new JCheckBox("Air Conditioning");
		windowsChkbx = new JCheckBox("Power Windows");
		transmissionChkbx = new JCheckBox("Standard Transmission");
		submitBtn = new JButton("Submit");
		
		optionsPanel.add(header3);
		
		optionsPanel.add(Box.createRigidArea(new Dimension(0, 10)));

		optionsPanel.add(airChkbx);
		
		optionsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		
		optionsPanel.add(windowsChkbx);
		
		optionsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		
		optionsPanel.add(transmissionChkbx);
		
		optionsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		
		optionsPanel.add(submitBtn);
		
	}
	
	//Main Method
	
	public static void main(String [] args)
	{
		new EF_UsedCarApp();
	}
	
}
//end class