phase2 sol + frame Color + update the table

This commit is contained in:
Asaad Dadoush 2020-12-09 00:56:13 +03:00
parent afb8f0982c
commit c5c89e30e8

View File

@ -37,6 +37,8 @@ public class MakkahCity {
private static JFrame makkahFrame; private static JFrame makkahFrame;
private static JTable streetTable; private static JTable streetTable;
private static JTable districtTable; private static JTable districtTable;
private static JLabel lblDate;
public static void main(String[] args) { public static void main(String[] args) {
@ -59,6 +61,9 @@ public class MakkahCity {
makeRoutes(); makeRoutes();
// Vehicle car = traceCar();
//GUI //GUI
autoModeCheckBox = new Checkbox(); autoModeCheckBox = new Checkbox();
makkahFrame = new JFrame("Streets"); makkahFrame = new JFrame("Streets");
@ -137,28 +142,28 @@ public class MakkahCity {
//Buttons //Buttons
JButton btnViewRoutes = new JButton("View Routes"); JButton btnViewRoutes = new JButton("View Routes");
btnViewRoutes.setBounds(1678, 39, 184, 29); btnViewRoutes.setBounds(1384, 35, 184, 29);
makkahFrame.getContentPane().add(btnViewRoutes); makkahFrame.getContentPane().add(btnViewRoutes);
btnViewRoutes.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewRoutes.setFont(new Font("Rockwell", Font.PLAIN, 16));
btnViewRoutes.setBackground(new Color(9,9,9)); btnViewRoutes.setBackground(new Color(9,9,9));
btnViewRoutes.setForeground(Color.white); btnViewRoutes.setForeground(Color.white);
JButton btnViewBuses = new JButton("View Buses"); JButton btnViewBuses = new JButton("View Buses");
btnViewBuses.setBounds(1678, 79, 184, 29); btnViewBuses.setBounds(1384, 75, 184, 29);
makkahFrame.getContentPane().add(btnViewBuses); makkahFrame.getContentPane().add(btnViewBuses);
btnViewBuses.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
btnViewBuses.setBackground(new Color(9,9,9)); btnViewBuses.setBackground(new Color(9,9,9));
btnViewBuses.setForeground(Color.white); btnViewBuses.setForeground(Color.white);
JButton btnViewCampaigns = new JButton("View Campaigns"); JButton btnViewCampaigns = new JButton("View Campaigns");
btnViewCampaigns.setBounds(1678, 119, 184, 29); btnViewCampaigns.setBounds(1384, 115, 184, 29);
makkahFrame.getContentPane().add(btnViewCampaigns); makkahFrame.getContentPane().add(btnViewCampaigns);
btnViewCampaigns.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewCampaigns.setFont(new Font("Rockwell", Font.PLAIN, 16));
btnViewCampaigns.setBackground(new Color(9,9,9)); btnViewCampaigns.setBackground(new Color(9,9,9));
btnViewCampaigns.setForeground(Color.white); btnViewCampaigns.setForeground(Color.white);
JButton btnViewStreet = new JButton("View Street"); JButton btnViewStreet = new JButton("View Street");
btnViewStreet.setBounds(1678, 159, 184, 29); btnViewStreet.setBounds(1384, 156, 184, 29);
makkahFrame.getContentPane().add(btnViewStreet); makkahFrame.getContentPane().add(btnViewStreet);
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
btnViewStreet.setBackground(new Color(9,9,9)); btnViewStreet.setBackground(new Color(9,9,9));
@ -168,7 +173,7 @@ public class MakkahCity {
btnExit.setBackground(new Color(9,9,9)); btnExit.setBackground(new Color(9,9,9));
btnExit.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnExit.setFont(new Font("Rockwell", Font.PLAIN, 16));
btnExit.setForeground(Color.white); btnExit.setForeground(Color.white);
btnExit.setBounds(1790, 920, 72, 23); btnExit.setBounds(1427, 908, 184, 23);
makkahFrame.getContentPane().add(btnExit); makkahFrame.getContentPane().add(btnExit);
btnExit.addActionListener(actionEvent -> exit_flag = true); btnExit.addActionListener(actionEvent -> exit_flag = true);
@ -183,16 +188,16 @@ public class MakkahCity {
lblDistrict.setForeground(new Color(255, 255, 255)); lblDistrict.setForeground(new Color(255, 255, 255));
lblDistrict.setBounds(61, 757, 166, 23); lblDistrict.setBounds(61, 757, 166, 23);
JLabel lblTime = new JLabel("Time"); JLabel lblTime = new JLabel("Time: ");
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblTime.setForeground(new Color(255, 255, 255)); lblTime.setForeground(new Color(255, 255, 255));
lblTime.setBounds(50, 11, 72, 14); lblTime.setBounds(50, 11, 72, 14);
//window //window
makkahFrame.getContentPane().setBackground(new Color(0, 0, 0)); makkahFrame.getContentPane().setBackground(new Color(70, 70, 70));
makkahFrame.getContentPane().setForeground(SystemColor.inactiveCaptionBorder); makkahFrame.getContentPane().setForeground(SystemColor.inactiveCaptionBorder);
makkahFrame.setBounds(100,100,1909,1019); makkahFrame.setBounds(100,100,1637,1019);
makkahFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); makkahFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
makkahFrame.getContentPane().setLayout(null); makkahFrame.getContentPane().setLayout(null);
makkahFrame.setLocationRelativeTo(null); makkahFrame.setLocationRelativeTo(null);
@ -202,6 +207,12 @@ public class MakkahCity {
makkahFrame.getContentPane().add(lblStreets); makkahFrame.getContentPane().add(lblStreets);
makkahFrame.setVisible(true); makkahFrame.setVisible(true);
makkahFrame.getContentPane().add(lblTime); makkahFrame.getContentPane().add(lblTime);
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblDate.setForeground(Color.WHITE);
lblDate.setBounds(107, 4, 326, 29);
makkahFrame.getContentPane().add(lblDate);
makkahFrame.revalidate(); makkahFrame.revalidate();
//Set Routes for Campaigns //Set Routes for Campaigns
@ -225,7 +236,7 @@ public class MakkahCity {
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
if (vehicle.getCurrentStreet() == null && if (vehicle.getCurrentStreet() == null &&
firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) % 3 == 0 && firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) % 2 == 0 &&
route.getStreets()[0].capcityPoint(0,1000) < 1) { route.getStreets()[0].capcityPoint(0,1000) < 1) {
vehicle.setCurrentStreet(route.getStreets()[0]); vehicle.setCurrentStreet(route.getStreets()[0]);
} }
@ -247,7 +258,9 @@ public class MakkahCity {
} }
} }
if (isAllArrived() && allArrivedToArafatTime == null) allArrivedToArafatTime = (Date)currenttimeManager.getCurrentTime().clone(); if (isAllArrived() && allArrivedToArafatTime == null) allArrivedToArafatTime = (Date)currenttimeManager.getCurrentTime().clone();
updateStreetFrame();
firstDayTimeMan.step(Calendar.MINUTE, 1); firstDayTimeMan.step(Calendar.MINUTE, 1);
// System.out.println(car);
} }
currenttimeManager = lastDayTimeMan; currenttimeManager = lastDayTimeMan;
@ -262,6 +275,7 @@ public class MakkahCity {
addCivilVehicleNoise(); addCivilVehicleNoise();
System.out.println("***************STARTING LAST DAY***************"); System.out.println("***************STARTING LAST DAY***************");
setRoutesForCampaigns(Mashier.MINA);
while(!lastDayTimeMan.isEnded()) { while(!lastDayTimeMan.isEnded()) {
checkInput(); checkInput();
//Start of Every hour //Start of Every hour
@ -278,10 +292,11 @@ public class MakkahCity {
clearDoneCivilVehicles(); clearDoneCivilVehicles();
addCivilVehicleNoise(); addCivilVehicleNoise();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
if (vehicle.getRoute() == null)
continue;
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
if (vehicle.getCurrentStreet() == null && if (vehicle.getCurrentStreet() == null &&
lastDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) % 3 == 0 &&
route.getStreets()[0].capcityPoint(0,1000) < 1) { route.getStreets()[0].capcityPoint(0,1000) < 1) {
vehicle.setCurrentStreet(route.getStreets()[0]); vehicle.setCurrentStreet(route.getStreets()[0]);
} }
@ -309,6 +324,17 @@ public class MakkahCity {
inputListener.pause(); inputListener.pause();
startMenu(); startMenu();
} }
private static Vehicle traceCar() {
for(int x = 20000; x < listOfVehicles.size(); x++) {
if(listOfVehicles.get(x) instanceof Bus)
if(((Bus)listOfVehicles.get(x)).getCampaign().getHotelDistrict() == District.ALAZIZIYA) {
return listOfVehicles.get(x);
}
}
return null;
}
private static void checkInput() { private static void checkInput() {
String input = ""; String input = "";
@ -458,7 +484,7 @@ public class MakkahCity {
private static void setRoutesForCampaigns(Mashier mashier) { private static void setRoutesForCampaigns(Mashier mashier) {
for (Campaign camp : listOfCampaigns){ for (Campaign camp : listOfCampaigns){
if (camp.getVehicles().get(0).getCurrentStreet() == null) { if(camp.getVehicles().get(0).getCurrentStreet() == null) {
isAllRoutSet = false; isAllRoutSet = false;
camp.setRoute(getBestRoute(camp, mashier)); camp.setRoute(getBestRoute(camp, mashier));
} }
@ -483,7 +509,7 @@ public class MakkahCity {
stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()] = new Street(4850,4, StreetNames.FOURTH_HIGHWAY2); stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()] = new Street(4850,4, StreetNames.FOURTH_HIGHWAY2);
stdStreet[StreetNames.FOURTH_HIGHWAY3.ordinal()] = new Street(4500,4, StreetNames.FOURTH_HIGHWAY3); stdStreet[StreetNames.FOURTH_HIGHWAY3.ordinal()] = new Street(4500,4, StreetNames.FOURTH_HIGHWAY3);
stdStreet[StreetNames.THIRD_HIGHWAY.ordinal()] = new Street(8200,3, StreetNames.THIRD_HIGHWAY); stdStreet[StreetNames.THIRD_HIGHWAY.ordinal()] = new Street(8200,3, StreetNames.THIRD_HIGHWAY);
stdStreet[StreetNames.STREET1.ordinal()] = new Street(7800,3, StreetNames.STREET1); stdStreet[StreetNames.STREET1.ordinal()] = new Street(7800,4, StreetNames.STREET1);
stdStreet[StreetNames.STREET2.ordinal()] = new Street(2400,3,StreetNames.STREET2); stdStreet[StreetNames.STREET2.ordinal()] = new Street(2400,3,StreetNames.STREET2);
stdStreet[StreetNames.STREET3.ordinal()] = new Street(4800,2, StreetNames.STREET3); stdStreet[StreetNames.STREET3.ordinal()] = new Street(4800,2, StreetNames.STREET3);
stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()] = new Street(3800,3,StreetNames.JABAL_THAWR_STREET); stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()] = new Street(3800,3,StreetNames.JABAL_THAWR_STREET);
@ -689,13 +715,17 @@ public class MakkahCity {
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict()); Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
routes = sortRoutes(routes); routes = sortRoutes(routes);
for (Route r : routes) { for (Route r : routes) {
if(r.getMashier() == Mashier.ARAFAT && r.getHotelArea() == District.ALHIJRA) {
return r;
}
if (r.getMashier() == mashier){ if (r.getMashier() == mashier){
if (r.capcity() < 70) if (r.capcity() < 70) {
return r;
else if (r.getHotelArea() == District.ALAZIZIYA)
return r; return r;
} }
else if (r.getHotelArea() == District.ALAZIZIYA)
return r;
} }
}
return null; return null;
} }
@ -937,4 +967,22 @@ public class MakkahCity {
} }
return buses; return buses;
} }
static void updateStreetFrame() {
Object[][] streetData = new Object[stdStreet.length][6];
for (int i = 0; i < stdStreet.length; i++) {
streetData[i][0] = stdStreet[i].getName().name();
streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
streetData[i][2] = stdStreet[i].getVehicles().size();
streetData[i][3] = stdStreet[i].getNumberOfBuses();
streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
streetData[i][5] = avgTimeOnStreet(stdStreet[i]);
}
for (int i = 0; i < streetData.length; i++) {
for (int j = 0; j < streetData[i].length; j++) {
streetTable.setValueAt(streetData[i][j], i, j);
}
}
lblDate.setText(currenttimeManager.getCurrentTime().toString());
}
} }