Add toString to GUI_ViewBuses

This commit is contained in:
EngOsamah 2020-12-17 01:11:45 +03:00
parent 67c81d22d6
commit 1db0ce7ca7
2 changed files with 24 additions and 2 deletions

View File

@ -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();
}

View File

@ -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> 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);
}