/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ica2;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.TextField;
import java.util.Vector;
import javax.swing.border.Border;
import javax.swing.JOptionPane;
/**
*
* @author n3098463
*/
public class GUI extends JPanel implements MouseListener {
JPanel southPark;
JPanel northPark;
JPanel btns;
JPanel carPark;
JButton addCar;
JLabel CarSpace;
JLabel LorrySpace;
int i;
int L;
int C;
int c;
String b[] = {"Add Car", "Add Lorry", "Add Coach", "Clear All", "Save", "Load", "Current Total", "Total for day"};
JButton[] buttons = new JButton[8];
GUI() {
//*******************************************Vector ********************************************************
//*********************************************BUTTON PANEL**************************************************
btns = new JPanel();
btns.setLayout(new GridLayout(8, 1));
btns.setVisible(true);
btns.addMouseListener(this);
//btns.setPreferredSize(new Dimension(150, 200));
//(int width, int height)
//**************************************ADDING THE BUTTONS ON THE PANEL***************************************
for (i = 0; i < buttons.length; i++) {
buttons[i] = new JButton(b[i]);
buttons[i].setPreferredSize(new Dimension(200, 70));
btns.add(buttons[i]);
buttons[i].addMouseListener(this);
}
//***************************************CAR PARK PANEL*****************************************************
carPark = new JPanel();
carPark.setVisible(true);
//this.add(carPark, BorderLayout.CENTER);
carPark.setLayout(new BorderLayout());
//****************************************NORTH PANEL (LORRYS & COACH)***************************************
northPark = new JPanel();
northPark.setVisible(true); //900,790
carPark.add(northPark, BorderLayout.NORTH);
northPark.setPreferredSize(new Dimension(600, 260));
//northPark.setBackground(Color.RED);
northPark.setLayout(new GridLayout(1, 4));
//************************************* ARRAY FOR JLABELS LORRYS *******************************************
JLabel[] LorrySpace = new JLabel[4];
// String lS[] = {"1", "2", "3", "4"};
for (L = 0; L < LorrySpace.length; L++) {
LorrySpace[L] = new JLabel();
Border borderLorry = BorderFactory.createLineBorder(Color.RED, 2);
LorrySpace[L].setBorder(borderLorry);
LorrySpace[L].setPreferredSize(new Dimension(75, 270));
northPark.add(LorrySpace[L]);
}
//*************************************SOUTH PANEL (CARS) **************************************************
southPark = new JPanel();
southPark.setVisible(true);
carPark.add(southPark, BorderLayout.SOUTH);
//southPark.setPreferredSize(new Dimension(75, 100));
//southPark.setBackground(Color.GREEN);
southPark.setLayout(new GridLayout(3, 4));
//**************************************** ARRAY FOR JLABELS CARS *****************************************
JLabel[] CarLabels = new JLabel[12];
//String cS[] = {"1", "2", "3", "4", "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" };
for (C = 0; C < CarLabels.length; C++) {
CarLabels[C] = new JLabel();
Border border = BorderFactory.createLineBorder(Color.RED, 2);
CarLabels[C].setBorder(border);
CarLabels[C].setPreferredSize(new Dimension(75, 100));
southPark.add(CarLabels[C]);
}
//************************************************************************************************************
this.add(btns, BorderLayout.WEST);
this.add(carPark);
}
public void mouseEntered(MouseEvent me) {
}
public void mousePressed(MouseEvent me) {
if (me.getSource() == buttons[0]) { //"Add Car Button Click"
JPanel addCarPanel = new JPanel();
addCarPanel.setLayout(new GridLayout(4, 2));
addCarPanel.add(new JLabel("Reg no."));
JTextField regNumField = new JTextField(8);
addCarPanel.add(regNumField);
addCarPanel.add(new JLabel("Length. "));
JTextField lengthField = new JTextField(3);
addCarPanel.add(lengthField);
JCheckBox disabledBadge = new JCheckBox("");
addCarPanel.add(new JLabel("Disabled Badge "));
addCarPanel.add(disabledBadge);
addCarPanel.add(new JLabel("Number Of Hours "));
JTextField hours = new JTextField(3);
addCarPanel.add(hours);
int optionCar = JOptionPane.showConfirmDialog(this, addCarPanel, "Add Car", JOptionPane.OK_CANCEL_OPTION);
if (optionCar == JOptionPane.OK_OPTION) {
System.out.println("Reg num entered: " + regNumField.getText());
System.out.println("Length of Car: " + lengthField.getText());
System.out.println("Disabled Badge: " + disabledBadge.isSelected());
System.out.println("Number of hours: " + hours.getText());
//CarLabels[] = new ImageIcon("images/car.jpg");
//Carlabels.setIcon(car);
double intLength = Double.parseDouble(lengthField.getText());
int h = Integer.parseInt(hours.getText());
Car CarNew = new Car(regNumField.getText(), intLength, disabledBadge.isSelected(), h);
}
}
else if (me.getSource() == buttons[1]) { //"Add Lorry Button Click"
JPanel addLorryPanel = new JPanel();
addLorryPanel.setLayout(new GridLayout(4, 2));
addLorryPanel.add(new JLabel("Reg no."));
JTextField regNumField = new JTextField(8);
addLorryPanel.add(regNumField);
addLorryPanel.add(new JLabel("Weight(KG). "));
JTextField weight = new JTextField(3);
addLorryPanel.add(weight);
addLorryPanel.add(new JLabel("Number Of Days "));
JTextField numOfDays = new JTextField(3);
addLorryPanel.add(numOfDays);
int optionLorry = JOptionPane.showConfirmDialog(this, addLorryPanel, "Add Lorry", JOptionPane.OK_CANCEL_OPTION);
if (optionLorry == JOptionPane.OK_OPTION) {
// Lorry.CalcCharge();
System.out.println("Reg num entered: " + regNumField.getText());
System.out.println("Weight Of Lorry: " + weight.getText());
System.out.println("Days Staying: " + numOfDays.getText());
//ImageIcon lorry = new ImageIcon ("*IMAGE PATH HERE*");
double intWeight = Double.parseDouble(weight.getText());
int d = Integer.parseInt(numOfDays.getText());
Lorry LorryNew = new Lorry(regNumField.getText(), intWeight, d );
}
} else if (me.getSource() == buttons[2]) { //"Add Coach Button Click"
JPanel addCoachPanel = new JPanel();
addCoachPanel.setLayout(new GridLayout(4, 2));
addCoachPanel.add(new JLabel("Reg no."));
JTextField regNumField = new JTextField(8);
addCoachPanel.add(regNumField);
addCoachPanel.add(new JLabel("Number Of Passengers "));
JTextField Passengers = new JTextField(3);
addCoachPanel.add(Passengers);
JCheckBox touristOperator = new JCheckBox("");
addCoachPanel.add(new JLabel("Tourist Operator "));
addCoachPanel.add(touristOperator);
int optionCoach = JOptionPane.showConfirmDialog(this, addCoachPanel, "Add Coach", JOptionPane.OK_CANCEL_OPTION);
if (optionCoach == JOptionPane.OK_OPTION) {
// Lorry.CalcCharge();
System.out.println("Reg num entered: " + regNumField.getText());
System.out.println("Number Of Pass': " + Passengers.getText());
System.out.println("Tourist Operator " + touristOperator.isSelected());
//ImageIcon coach = new ImageIcon ("*IMAGE PATH HERE*");
int intPassengers = Integer.parseInt(Passengers.getText());
Coach coachNew = new Coach(regNumField.getText(), intPassengers, touristOperator.isSelected());
} else if (me.getSource() == buttons[3]) {
System.out.println("Clear All");
} else if (me.getSource() == buttons[4]) {
System.out.println("Save");
} else if (me.getSource() == buttons[5]) {
System.out.println("Load");
} else if (me.getSource() == buttons[6]) {
System.out.println("Current Total");
} else if (me.getSource() == buttons[7]) {
System.out.println("Total");
}
}
}
public void mouseReleased(MouseEvent me) {
}
public void mouseClicked(MouseEvent me) {
}
public void mouseExited(MouseEvent me) {
}
/*
* public void addCar() {
JPanel addCarPanel = new JPanel();
addCarPanel.setLayout(new GridLayout(4, 2));
addCarPanel.add(new JLabel("Reg no."));
JTextField regNumField = new JTextField(8);
addCarPanel.add(regNumField);
addCarPanel.add(new JLabel("Length. "));
JTextField lengthField = new JTextField(3);
addCarPanel.add(lengthField);
JCheckBox disabledBadge = new JCheckBox("");
addCarPanel.add(new JLabel("Disabled Badge "));
addCarPanel.add(disabledBadge);
addCarPanel.add(new JLabel("Number Of Hours "));
JTextField hours = new JTextField(3);
addCarPanel.add(hours);
int optionCar = JOptionPane.showConfirmDialog(this, addCarPanel, "Add Car", JOptionPane.OK_CANCEL_OPTION);
if (optionCar == JOptionPane.OK_OPTION) {
System.out.println("Reg num entered: " + regNumField.getText());
System.out.println("Length of Car: " + lengthField.getText());
System.out.println("Disabled Badge: " + disabledBadge.isSelected());
System.out.println("Number of hours: " + hours.getText());
//CarLabels[] = new ImageIcon("images/car.jpg");
//Carlabels.setIcon(car);
double intLength = Double.parseDouble(lengthField.getText());
int h = Integer.parseInt(hours.getText());
Car CarNew = new Car(regNumField.getText(), intLength, disabledBadge.isSelected(), h);
}
}
public void addLorry() {
JPanel addLorryPanel = new JPanel();
addLorryPanel.setLayout(new GridLayout(4, 2));
addLorryPanel.add(new JLabel("Reg no."));
JTextField regNumField = new JTextField(8);
addLorryPanel.add(regNumField);
addLorryPanel.add(new JLabel("Weight(KG). "));
JTextField weight = new JTextField(3);
addLorryPanel.add(weight);
addLorryPanel.add(new JLabel("Number Of Days "));
JTextField numOfDays = new JTextField(3);
addLorryPanel.add(numOfDays);
int optionLorry = JOptionPane.showConfirmDialog(this, addLorryPanel, "Add Lorry", JOptionPane.OK_CANCEL_OPTION);
if (optionLorry == JOptionPane.OK_OPTION) {
// Lorry.CalcCharge();
System.out.println("Reg num entered: " + regNumField.getText());
System.out.println("Weight Of Lorry: " + weight.getText());
System.out.println("Days Staying: " + numOfDays.getText());
//ImageIcon lorry = new ImageIcon ("*IMAGE PATH HERE*");
double intWeight = Double.parseDouble(weight.getText());
int d = Integer.parseInt(numOfDays.getText());
Lorry LorryNew = new Lorry(regNumField.getText(), intWeight, d );
}
}
public void addCoach() {
JPanel addCoachPanel = new JPanel();
addCoachPanel.setLayout(new GridLayout(4, 2));
addCoachPanel.add(new JLabel("Reg no."));
JTextField regNumField = new JTextField(8);
addCoachPanel.add(regNumField);
addCoachPanel.add(new JLabel("Weight(KG). "));
JTextField weightField = new JTextField(3);
addCoachPanel.add(weightField);
addCoachPanel.add(new JLabel("Number Of Days "));
JTextField days = new JTextField(3);
addCoachPanel.add(days);
int optionCoach = JOptionPane.showConfirmDialog(this, addCoachPanel, "Add Lorry", JOptionPane.OK_CANCEL_OPTION);
}
public void clearAll() {
}
public void Save() {
}
public void Load() {
}
public void currentTotal() {
}
public void overallTotal() {
}
*/
}