From da959a5cd3c28380e03b3ee83e6ca3b14e8f6bbc Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Mon, 7 Dec 2020 03:24:46 +0300 Subject: [PATCH 1/4] simple Street table --- src/MakkahCity.java | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/MakkahCity.java b/src/MakkahCity.java index ad8128e..77632ca 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -1,4 +1,9 @@ -import java.util.*; +import javax.swing.*; +import javax.swing.table.TableColumn; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.*; public class MakkahCity { @@ -47,6 +52,34 @@ public class MakkahCity { makeRoutes(); + Object[][] streetData = new Object[stdStreet.length][6]; + String[] colNames = new String[]{ + "Street name", + "Street Load", + "Total", + "Buses", + "Local Vehicles", + "Avg. Time" + }; + 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]); + } + JFrame frame = new JFrame("Streets"); + JPanel panel = new JPanel(new GridLayout()); + JTable table = new JTable(streetData,colNames); + Button btn = new Button("OK"); + panel.add(table); + panel.add(btn); + frame.add(panel); + frame.setSize(500,500); + frame.setVisible(true); + + //Set Routes for Campaigns setRoutesForCampaigns(Mashier.ARAFAT); while(!firstDayTimeMan.isEnded()) { From 7d5f3452ad761983ca39c600f271e8d44d247146 Mon Sep 17 00:00:00 2001 From: Asaad Dadoush Date: Mon, 7 Dec 2020 11:01:20 +0300 Subject: [PATCH 2/4] GUI Woring heeeeeeeee :D --- src/MakkahCity.java | 97 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/src/MakkahCity.java b/src/MakkahCity.java index 77632ca..6c18f85 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -1,4 +1,5 @@ import javax.swing.*; +import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import java.awt.*; import java.awt.event.ActionEvent; @@ -51,16 +52,10 @@ public class MakkahCity { addCivilVehicleNoise(); makeRoutes(); - + //table + JFrame f = new JFrame("Streets"); Object[][] streetData = new Object[stdStreet.length][6]; - String[] colNames = new String[]{ - "Street name", - "Street Load", - "Total", - "Buses", - "Local Vehicles", - "Avg. Time" - }; + for (int i = 0; i < stdStreet.length; i++) { streetData[i][0] = stdStreet[i].getName().name(); streetData[i][1] = stdStreet[i].getPercentRemainingCapacity(); @@ -69,16 +64,80 @@ public class MakkahCity { streetData[i][4] = stdStreet[i].getNumberOfLocalCars(); streetData[i][5] = avgTimeOnStreet(stdStreet[i]); } - JFrame frame = new JFrame("Streets"); - JPanel panel = new JPanel(new GridLayout()); - JTable table = new JTable(streetData,colNames); - Button btn = new Button("OK"); - panel.add(table); - panel.add(btn); - frame.add(panel); - frame.setSize(500,500); - frame.setVisible(true); - + + String[] colNames = {"Street name", "Street Load", "Total", "Buses", + "Local Vehicles", + "Avg. Time"}; + + JTable table = new JTable(streetData,colNames); + DefaultTableModel model = new DefaultTableModel(); + model.setColumnIdentifiers(colNames); + table.getTableHeader().setBackground(Color.lightGray); + table.setBackground(Color.DARK_GRAY); + table.setForeground(Color.white); + table.setSelectionBackground(Color.BLUE); + table.setGridColor(Color.white); + table.setSelectionForeground(Color.white); + table.setFont(new Font("Tahoma", Font.PLAIN, 12)); + table.setRowHeight(30); + table.setAutoCreateRowSorter(true); + + JScrollPane scroll = new JScrollPane(table); + scroll.setBounds(10,11,871,383); + + //buttons + JButton btnViewBuses = new JButton("View Buses"); + btnViewBuses.setForeground(new Color(0, 0, 0)); + btnViewBuses.setFont(UIManager.getFont("Button.font")); + btnViewBuses.setBackground(new Color(211, 211, 211)); + btnViewBuses.setBounds(67, 428, 121, 23); + f.getContentPane().add(btnViewBuses); + + JButton btnViewStreet = new JButton("View Street"); + btnViewStreet.setBackground(new Color(211, 211, 211)); + btnViewStreet.setForeground(new Color(0, 0, 0)); + btnViewStreet.setBounds(211, 428, 103, 23); + f.getContentPane().add(btnViewStreet); + + JButton btnViewCampaigns = new JButton("View Campaigns"); + btnViewCampaigns.setForeground(new Color(0, 0, 0)); + btnViewCampaigns.setBackground(new Color(211, 211, 211)); + btnViewCampaigns.setBounds(336, 428, 137, 23); + f.getContentPane().add(btnViewCampaigns); + + JButton btnNewButton_2 = new JButton("View Routes"); + btnNewButton_2.setBackground(new Color(211, 211, 211)); + btnNewButton_2.setForeground(new Color(0, 0, 0)); + btnNewButton_2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); + btnNewButton_2.setBounds(496, 428, 113, 23); + f.getContentPane().add(btnNewButton_2); + + JButton btnNewButton_3 = new JButton("Print Report"); + btnNewButton_3.setForeground(new Color(0, 0, 0)); + btnNewButton_3.setBackground(new Color(211, 211, 211)); + btnNewButton_3.setBounds(633, 428, 113, 23); + f.getContentPane().add(btnNewButton_3); + + JButton btnNewButton_4 = new JButton("Exit"); + btnNewButton_4.setForeground(new Color(0, 0, 0)); + btnNewButton_4.setBackground(new Color(211, 211, 211)); + btnNewButton_4.setBounds(766, 428, 72, 23); + f.getContentPane().add(btnNewButton_4); + + //window + f.getContentPane().setBackground(new Color(0, 0, 0)); + f.getContentPane().setForeground(SystemColor.inactiveCaptionBorder); + f.setBounds(100,100,907,514); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.getContentPane().setLayout(null); + f.setLocationRelativeTo(null); + f.getContentPane().add(scroll); + f.setVisible(true); + f.setLocation(700, 200); + f.revalidate(); //Set Routes for Campaigns setRoutesForCampaigns(Mashier.ARAFAT); From 192a482bb4a74a98ddb4b3e11942dcea25dc3ea2 Mon Sep 17 00:00:00 2001 From: Asaad Dadoush Date: Mon, 7 Dec 2020 11:12:23 +0300 Subject: [PATCH 3/4] edit some swing --- src/MakkahCity.java | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/MakkahCity.java b/src/MakkahCity.java index 6c18f85..0a3f63d 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -105,27 +105,23 @@ public class MakkahCity { btnViewCampaigns.setBounds(336, 428, 137, 23); f.getContentPane().add(btnViewCampaigns); - JButton btnNewButton_2 = new JButton("View Routes"); - btnNewButton_2.setBackground(new Color(211, 211, 211)); - btnNewButton_2.setForeground(new Color(0, 0, 0)); - btnNewButton_2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - } - }); - btnNewButton_2.setBounds(496, 428, 113, 23); - f.getContentPane().add(btnNewButton_2); + JButton btnViewRoutes = new JButton("View Routes"); + btnViewRoutes.setBackground(new Color(211, 211, 211)); + btnViewRoutes.setForeground(new Color(0, 0, 0)); + btnViewRoutes.setBounds(496, 428, 113, 23); + f.getContentPane().add(btnViewRoutes); - JButton btnNewButton_3 = new JButton("Print Report"); - btnNewButton_3.setForeground(new Color(0, 0, 0)); - btnNewButton_3.setBackground(new Color(211, 211, 211)); - btnNewButton_3.setBounds(633, 428, 113, 23); - f.getContentPane().add(btnNewButton_3); + JButton btnPrintReport = new JButton("Print Report"); + btnPrintReport.setForeground(new Color(0, 0, 0)); + btnPrintReport.setBackground(new Color(211, 211, 211)); + btnPrintReport.setBounds(633, 428, 113, 23); + f.getContentPane().add(btnPrintReport); - JButton btnNewButton_4 = new JButton("Exit"); - btnNewButton_4.setForeground(new Color(0, 0, 0)); - btnNewButton_4.setBackground(new Color(211, 211, 211)); - btnNewButton_4.setBounds(766, 428, 72, 23); - f.getContentPane().add(btnNewButton_4); + JButton btnExit = new JButton("Exit"); + btnExit.setForeground(new Color(0, 0, 0)); + btnExit.setBackground(new Color(211, 211, 211)); + btnExit.setBounds(766, 428, 72, 23); + f.getContentPane().add(btnExit); //window f.getContentPane().setBackground(new Color(0, 0, 0)); From bb17d9180ea018732719481977284a60f9bd7e3d Mon Sep 17 00:00:00 2001 From: Asaad Dadoush Date: Mon, 7 Dec 2020 11:13:37 +0300 Subject: [PATCH 4/4] edit some swing --- src/MakkahCity.java | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/MakkahCity.java b/src/MakkahCity.java index 0a3f63d..b2201b5 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -53,7 +53,7 @@ public class MakkahCity { makeRoutes(); //table - JFrame f = new JFrame("Streets"); + JFrame frame = new JFrame("Streets"); Object[][] streetData = new Object[stdStreet.length][6]; for (int i = 0; i < stdStreet.length; i++) { @@ -91,49 +91,49 @@ public class MakkahCity { btnViewBuses.setFont(UIManager.getFont("Button.font")); btnViewBuses.setBackground(new Color(211, 211, 211)); btnViewBuses.setBounds(67, 428, 121, 23); - f.getContentPane().add(btnViewBuses); + frame.getContentPane().add(btnViewBuses); JButton btnViewStreet = new JButton("View Street"); btnViewStreet.setBackground(new Color(211, 211, 211)); btnViewStreet.setForeground(new Color(0, 0, 0)); btnViewStreet.setBounds(211, 428, 103, 23); - f.getContentPane().add(btnViewStreet); + frame.getContentPane().add(btnViewStreet); JButton btnViewCampaigns = new JButton("View Campaigns"); btnViewCampaigns.setForeground(new Color(0, 0, 0)); btnViewCampaigns.setBackground(new Color(211, 211, 211)); btnViewCampaigns.setBounds(336, 428, 137, 23); - f.getContentPane().add(btnViewCampaigns); + frame.getContentPane().add(btnViewCampaigns); JButton btnViewRoutes = new JButton("View Routes"); btnViewRoutes.setBackground(new Color(211, 211, 211)); btnViewRoutes.setForeground(new Color(0, 0, 0)); btnViewRoutes.setBounds(496, 428, 113, 23); - f.getContentPane().add(btnViewRoutes); + frame.getContentPane().add(btnViewRoutes); JButton btnPrintReport = new JButton("Print Report"); btnPrintReport.setForeground(new Color(0, 0, 0)); btnPrintReport.setBackground(new Color(211, 211, 211)); btnPrintReport.setBounds(633, 428, 113, 23); - f.getContentPane().add(btnPrintReport); + frame.getContentPane().add(btnPrintReport); JButton btnExit = new JButton("Exit"); btnExit.setForeground(new Color(0, 0, 0)); btnExit.setBackground(new Color(211, 211, 211)); btnExit.setBounds(766, 428, 72, 23); - f.getContentPane().add(btnExit); + frame.getContentPane().add(btnExit); //window - f.getContentPane().setBackground(new Color(0, 0, 0)); - f.getContentPane().setForeground(SystemColor.inactiveCaptionBorder); - f.setBounds(100,100,907,514); - f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - f.getContentPane().setLayout(null); - f.setLocationRelativeTo(null); - f.getContentPane().add(scroll); - f.setVisible(true); - f.setLocation(700, 200); - f.revalidate(); + frame.getContentPane().setBackground(new Color(0, 0, 0)); + frame.getContentPane().setForeground(SystemColor.inactiveCaptionBorder); + frame.setBounds(100,100,907,514); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().setLayout(null); + frame.setLocationRelativeTo(null); + frame.getContentPane().add(scroll); + frame.setVisible(true); + frame.setLocation(700, 200); + frame.revalidate(); //Set Routes for Campaigns setRoutesForCampaigns(Mashier.ARAFAT);