From 1db0ce7ca7a9ffee991e8cefd06ea0bfc9fb5327 Mon Sep 17 00:00:00 2001 From: EngOsamah <74116947+EngOsamah@users.noreply.github.com> Date: Thu, 17 Dec 2020 01:11:45 +0300 Subject: [PATCH] Add toString to GUI_ViewBuses --- src/Bus.java | 2 +- src/GUI_ViewBuses.java | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Bus.java b/src/Bus.java index 8e5dc0c..82faa6c 100644 --- a/src/Bus.java +++ b/src/Bus.java @@ -33,7 +33,7 @@ public class Bus extends CivilVehicle { @Override public String toString() { StringBuilder s = new StringBuilder(); - s.append(String.format("\nID: %s, Campaign ID: %s\n",this.getUID() , getCampaign().getUID())); + s.append(String.format("ID: %s, Campaign ID: %s\n",this.getUID() , getCampaign().getUID())); s.append(super.toString()); return s.toString(); } diff --git a/src/GUI_ViewBuses.java b/src/GUI_ViewBuses.java index 71a216f..98b266f 100644 --- a/src/GUI_ViewBuses.java +++ b/src/GUI_ViewBuses.java @@ -9,6 +9,10 @@ import javax.swing.JButton; import java.awt.Color; import javax.swing.table.DefaultTableModel; import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.JTextField; +import javax.swing.DropMode; +import javax.swing.JTextPane; public class GUI_ViewBuses { @@ -26,10 +30,11 @@ public class GUI_ViewBuses { private static JButton Almansoor; private static JLabel lblTime; private static JLabel lblDate; - JLabel lblStatus; + private JLabel lblStatus; private JLabel lblDestination; private JLabel lblDistrict; private JLabel lblDistrictValue; + private JTextPane textPane; public GUI_ViewBuses(ArrayList campaign , PDate currenttimeManager) { @@ -75,6 +80,13 @@ public class GUI_ViewBuses { table.setCellSelectionEnabled(true); DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(busColNames); + ListSelectionModel model2 = table.getSelectionModel(); + model2.addListSelectionListener(e -> { + if (!model2.isSelectionEmpty()) { + int row = model2.getMinSelectionIndex(); + textPane.setText(((Bus)vehicles.get(row)).toString()); + } + }); table.getTableHeader().setBackground(new Color(17,17,17)); table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18)); table.getTableHeader().setForeground(Color.WHITE); @@ -169,6 +181,16 @@ public class GUI_ViewBuses { lblDistrictValue.setBounds(247, 371, 129, 12); frame.getContentPane().add(lblDistrictValue); + textPane = new JTextPane(); + textPane.setFont(new Font("Rockwell", Font.PLAIN, 16)); + textPane.setForeground(Color.WHITE); + textPane.setBackground(Color.BLACK); + + JScrollPane scrolltext = new JScrollPane(textPane); + scrolltext.setBounds(523, 271, 384, 133); + frame.getContentPane().add(scrolltext); + + frame.setVisible(true); }