Anonymous Anonymous - 4 months ago
430 0

No description

Java

Plugin.java

package com.cynigasm.projects.panels;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Plugin extends JFrame {
	
	public int i;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Plugin() {
//		Calls createContents() method
		createContents();
		
//		Closes application on window exit
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		Centres application screen
		setLocationRelativeTo(null);
//		Sets the applications dimensions (px,px)
		setSize(400,200);
//		Disables Resizing of the application
		setResizable(false);
		setTitle("Joe's Rental");
	}
	
	private void createContents() {
		JPanel myPanel = new JPanel();
		JPanel panelForm = new JPanel(new GridBagLayout());
		getContentPane().add(myPanel);
		myPanel.add(panelForm);
		
		GridBagConstraints g = new GridBagConstraints();
		g.anchor = GridBagConstraints.LINE_END;
		g.gridx = 0;
		g.gridy = 0;
		panelForm.add(new JLabel("First Name: "), g);
		g.gridy++;
		panelForm.add(new JLabel("Last Name: "), g);
		g.gridy++;
		panelForm.add(new JLabel("Email: "), g);
		g.gridy++;
		panelForm.add(new JLabel("Car Type: "), g);
		g.gridy++;
		panelForm.add(new JLabel("Rental Duration (Days): "), g);
		
		
		g.gridx = 1;
		g.gridy = 0;
		g.anchor = GridBagConstraints.LINE_START;
		panelForm.add(new JTextField(16), g);
		g.gridy++;
		panelForm.add(new JTextField(16), g);
		g.gridy++;
		panelForm.add(new JTextField(16), g);
		g.gridy++;
		
		String[] models = {"1","2","3","4","5"};
		JComboBox cars = new JComboBox(models);
		cars.setSelectedItem(0);
		panelForm.add(cars, g);
		g.gridy++;
		
		Integer[] numbers = {1,2,3,4,5,6,7};
		JComboBox timeperiod = new JComboBox(numbers);
		timeperiod.setSelectedItem(0);
		panelForm.add(timeperiod, g);
		g.gridy++;
		
		JButton confirm = new JButton();
		confirm.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				i = Integer.parseInt(timeperiod.getSelectedItem().toString());
			}
			
		});
		confirm.setText("Confirm Rental");
		panelForm.add(confirm, g);
		confirm.setAlignmentX(Component.CENTER_ALIGNMENT);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(() -> {
			new Plugin().setVisible(true);
		});
	}

}