Start GUI_ViewStreet class (#24)

Co-authored-by: HeshamTB <38921037+HeshamTB@users.noreply.github.com>
This commit is contained in:
EngOsamah 2020-12-11 16:40:25 +03:00 committed by GitHub
parent 556dc27d9c
commit a695ead32d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 134 additions and 51 deletions

View File

@ -4,11 +4,22 @@ import javax.swing.JLabel;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.awt.Font; import java.awt.Font;
import java.awt.Color;
import javax.swing.JScrollBar;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JScrollPane;
public class EventControll { public class EventControll {
private JFrame frame; private JFrame frame;
private JLabel lblNewLabel; //private JTextField textField;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
public static void main(String[] args) { public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() { EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
@ -28,19 +39,18 @@ public class EventControll {
private void initialize() { private void initialize() {
frame = new JFrame(); frame = new JFrame();
frame.setBounds(100, 100, 450, 300); frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(); for (int i = 0; i<10 ; i++) {
frame.getContentPane().add(panel, BorderLayout.CENTER); JTextField textField = new JTextField();
int x =(int)(((double)i/9.0)*255);
lblNewLabel = new JLabel(); textField.setBackground(new Color(255,x,0));
lblNewLabel.setFont(new Font("Rockwell", Font.PLAIN, 16)); frame.getContentPane().add(textField);
panel.add(lblNewLabel); textField.setColumns(10);
frame.setVisible(true); }
} }
public void setData(Object A) { public void setData(Object A) {
lblNewLabel.setText(A.toString()); //lblNewLabel.setText(A.toString());
} }
} }

View File

@ -31,29 +31,32 @@ public class GUI_ViewBuses {
private JLabel lblDistrict; private JLabel lblDistrict;
private JLabel lblDistrictValue; private JLabel lblDistrictValue;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() { public GUI_ViewBuses(ArrayList<Campaign> campaign , PDate currenttimeManager) {
public void run() { for (Campaign camp : campaign) {
try { switch (camp.getHotelDistrict()) {
GUI_ViewBuses window = new GUI_ViewBuses(); case ALAZIZIYA:
window.frame.setVisible(true); vehiclesAlazizya.add(camp.getVehicles().get(0));
} catch (Exception e) { break;
e.printStackTrace(); case ALHIJRA:
} vehiclesAlhijra.add(camp.getVehicles().get(0));
break;
case ALMANSOOR:
vehiclesAlmansoor.add(camp.getVehicles().get(0));
break;
default:
break;
} }
}
}); this.currenttimeManager = currenttimeManager;
makeFrame();
}
public GUI_ViewBuses() {
// makeFrame();
} }
private void makeFrame() { private void makeFrame() {
frame = new JFrame("Buses"); frame = new JFrame("Buses");
busData = new Object[vehicles.size()][6]; busData = new Object[vehicles.size()][6];
for (int i = 0; i < vehicles.size(); i++) { for (int i = 0; i < vehicles.size(); i++) {
busData[i][0] = vehicles.get(i).getUID(); busData[i][0] = vehicles.get(i).getUID();
if (vehicles.get(i).isMoving()) if (vehicles.get(i).isMoving())
@ -167,30 +170,9 @@ public class GUI_ViewBuses {
lblDistrictValue.setBounds(247, 371, 129, 12); lblDistrictValue.setBounds(247, 371, 129, 12);
frame.getContentPane().add(lblDistrictValue); frame.getContentPane().add(lblDistrictValue);
frame.setVisible(true); frame.setVisible(true);
} }
public void setData(ArrayList<Campaign> campaign , PDate currenttimeManager) {
for (Campaign camp : campaign) {
switch (camp.getHotelDistrict()) {
case ALAZIZIYA:
vehiclesAlazizya.add(camp.getVehicles().get(0));
break;
case ALHIJRA:
vehiclesAlhijra.add(camp.getVehicles().get(0));
break;
case ALMANSOOR:
vehiclesAlmansoor.add(camp.getVehicles().get(0));
break;
default:
break;
}
}
this.currenttimeManager = currenttimeManager;
makeFrame();
}
public void updateTable() { public void updateTable() {
busData = new Object[vehicles.size()][6]; busData = new Object[vehicles.size()][6];
@ -209,6 +191,7 @@ public class GUI_ViewBuses {
table.setModel(new DefaultTableModel(busData ,busColNames)); table.setModel(new DefaultTableModel(busData ,busColNames));
} }
public void updateVehicles(ArrayList<Vehicle> vehiclesDistrict) { public void updateVehicles(ArrayList<Vehicle> vehiclesDistrict) {
vehicles.clear(); vehicles.clear();
vehicles.addAll(vehiclesDistrict); vehicles.addAll(vehiclesDistrict);

88
src/GUI_ViewStreet.java Normal file
View File

@ -0,0 +1,88 @@
import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JList;
import javax.swing.AbstractListModel;
public class GUI_ViewStreet {
private static JFrame frame;
private static Street street;
private static Street[] stdStreet = new Street[StreetNames.values().length];
private static PDate currenttimeManager;
private static Object[][] busData;
private static String[] busColNames = {"ID", "District", "location","Progress", "trip time"};
private static JTable table;
public GUI_ViewStreet(Street[] streets, PDate currenttimeManager) {
this.stdStreet = streets;
this.currenttimeManager = currenttimeManager;
makeFrame();
}
private void makeFrame() {
street = stdStreet[0];
frame = new JFrame("Streets");
frame.getContentPane().setBackground(new Color(70, 70, 70));
frame.getContentPane().setForeground(new Color(0, 0, 0));
frame.setBounds(100,100,814,454);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setLocationRelativeTo(null);
busData = new Object[street.getVehicles().size()][6];
for (int i = 0; i < street.getVehicles().size(); i++) {
busData[i][0] = street.getVehicles().get(i).getUID();
if (street.getVehicles().get(i) instanceof Bus)
busData[i][1] = ((Bus)street.getVehicles().get(i)).getCampaign().getHotelDistrict().name();
else busData[i][1] = "Local Vehicle";
busData[i][2] = street.getVehicles().get(i).getCurrentLocation();
busData[i][3] = street.getVehicles().get(i).getProgress();
busData[i][4] = street.getVehicles().get(i).getTripTime();
}
table = new JTable(busData,busColNames);
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(busColNames);
table.getTableHeader().setBackground(new Color(17,17,17));
table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
table.getTableHeader().setForeground(Color.WHITE);
table.setModel(new DefaultTableModel(busData ,busColNames));
table.setBackground(new Color(17,17,17));
table.setForeground(Color.WHITE);
table.setGridColor(new Color(102, 102, 102));
table.setFont(new Font("Rockwell", Font.PLAIN, 18));
table.setRowHeight(25);
table.setAutoCreateRowSorter(true);
table.revalidate();
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(10, 168, 754, 236);
frame.getContentPane().add(scrollPane);
JList list = new JList();
list.setModel(new AbstractListModel() {
Street[] streets = stdStreet;
public int getSize() {
return stdStreet.length;
}
public Object getElementAt(int index) {
return streets[index].getName().name();
}
});
list.setBounds(10, 11, 118, 146);
JScrollPane scrollList = new JScrollPane(table);
scrollList.setBounds(10, 11, 118, 146);
frame.getContentPane().add(scrollList);
frame.setVisible(true);
}
}

View File

@ -163,8 +163,7 @@ public class MakkahCity {
btnViewBuses.setBackground(new Color(9,9,9)); btnViewBuses.setBackground(new Color(9,9,9));
btnViewBuses.setForeground(Color.white); btnViewBuses.setForeground(Color.white);
btnViewBuses.addActionListener(e -> { btnViewBuses.addActionListener(e -> {
GUI_ViewBuses t = new GUI_ViewBuses(); GUI_ViewBuses t = new GUI_ViewBuses(listOfCampaigns , currenttimeManager);
t.setData(listOfCampaigns , currenttimeManager);
}); });
JButton btnViewCampaigns = new JButton("View Campaigns"); JButton btnViewCampaigns = new JButton("View Campaigns");
@ -178,6 +177,9 @@ public class MakkahCity {
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));
btnViewStreet.setForeground(Color.white); btnViewStreet.setForeground(Color.white);
btnViewStreet.addActionListener(e -> {
GUI_ViewStreet t = new GUI_ViewStreet(stdStreet , currenttimeManager);
});
JButton btnExit = new JButton("Exit"); JButton btnExit = new JButton("Exit");
btnExit.setBackground(new Color(9,9,9)); btnExit.setBackground(new Color(9,9,9));