Start GUI_ViewStreet class (#24)
Co-authored-by: HeshamTB <38921037+HeshamTB@users.noreply.github.com>
This commit is contained in:
parent
556dc27d9c
commit
a695ead32d
@ -4,11 +4,22 @@ import javax.swing.JLabel;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JPanel;
|
||||
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 {
|
||||
|
||||
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) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
@ -28,19 +39,18 @@ public class EventControll {
|
||||
|
||||
private void initialize() {
|
||||
frame = new JFrame();
|
||||
frame.setBounds(100, 100, 450, 300);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
|
||||
lblNewLabel = new JLabel();
|
||||
lblNewLabel.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
panel.add(lblNewLabel);
|
||||
frame.setVisible(true);
|
||||
for (int i = 0; i<10 ; i++) {
|
||||
JTextField textField = new JTextField();
|
||||
int x =(int)(((double)i/9.0)*255);
|
||||
textField.setBackground(new Color(255,x,0));
|
||||
frame.getContentPane().add(textField);
|
||||
textField.setColumns(10);
|
||||
}
|
||||
}
|
||||
|
||||
public void setData(Object A) {
|
||||
lblNewLabel.setText(A.toString());
|
||||
//lblNewLabel.setText(A.toString());
|
||||
}
|
||||
}
|
||||
|
@ -31,29 +31,32 @@ public class GUI_ViewBuses {
|
||||
private JLabel lblDistrict;
|
||||
private JLabel lblDistrictValue;
|
||||
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
GUI_ViewBuses window = new GUI_ViewBuses();
|
||||
window.frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public GUI_ViewBuses(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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public GUI_ViewBuses() {
|
||||
// makeFrame();
|
||||
}
|
||||
this.currenttimeManager = currenttimeManager;
|
||||
makeFrame();
|
||||
}
|
||||
|
||||
|
||||
private void makeFrame() {
|
||||
frame = new JFrame("Buses");
|
||||
busData = new Object[vehicles.size()][6];
|
||||
|
||||
|
||||
for (int i = 0; i < vehicles.size(); i++) {
|
||||
busData[i][0] = vehicles.get(i).getUID();
|
||||
if (vehicles.get(i).isMoving())
|
||||
@ -167,30 +170,9 @@ public class GUI_ViewBuses {
|
||||
lblDistrictValue.setBounds(247, 371, 129, 12);
|
||||
frame.getContentPane().add(lblDistrictValue);
|
||||
|
||||
|
||||
|
||||
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() {
|
||||
busData = new Object[vehicles.size()][6];
|
||||
@ -209,6 +191,7 @@ public class GUI_ViewBuses {
|
||||
table.setModel(new DefaultTableModel(busData ,busColNames));
|
||||
}
|
||||
|
||||
|
||||
public void updateVehicles(ArrayList<Vehicle> vehiclesDistrict) {
|
||||
vehicles.clear();
|
||||
vehicles.addAll(vehiclesDistrict);
|
||||
|
88
src/GUI_ViewStreet.java
Normal file
88
src/GUI_ViewStreet.java
Normal 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);
|
||||
}
|
||||
}
|
@ -163,8 +163,7 @@ public class MakkahCity {
|
||||
btnViewBuses.setBackground(new Color(9,9,9));
|
||||
btnViewBuses.setForeground(Color.white);
|
||||
btnViewBuses.addActionListener(e -> {
|
||||
GUI_ViewBuses t = new GUI_ViewBuses();
|
||||
t.setData(listOfCampaigns , currenttimeManager);
|
||||
GUI_ViewBuses t = new GUI_ViewBuses(listOfCampaigns , currenttimeManager);
|
||||
});
|
||||
|
||||
JButton btnViewCampaigns = new JButton("View Campaigns");
|
||||
@ -178,6 +177,9 @@ public class MakkahCity {
|
||||
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
btnViewStreet.setBackground(new Color(9,9,9));
|
||||
btnViewStreet.setForeground(Color.white);
|
||||
btnViewStreet.addActionListener(e -> {
|
||||
GUI_ViewStreet t = new GUI_ViewStreet(stdStreet , currenttimeManager);
|
||||
});
|
||||
|
||||
JButton btnExit = new JButton("Exit");
|
||||
btnExit.setBackground(new Color(9,9,9));
|
||||
|
Loading…
Reference in New Issue
Block a user