//package PS5; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; import java.util.*; public class BusFrame extends JFrame { private JButton calcButton, quitButton; private JComboBox parkingBox; // Change in Logan parking cost private JTextField timeField; // Change in bus travel time private JTextField objectiveField; private BusDrawing drawArea; private BusSystem bSystem; // Need to instantiate private JPanel buttonHolder; private Container conPane; public static final int X = 700; // Size of drawArea public static final int Y = 500; // Size of drawArea public static void main(String[] args) { BusFrame frame = new BusFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); } public BusFrame() { conPane = getContentPane(); conPane.setLayout(new BorderLayout()); setSize(X, Y + 100); // Allow 100 pixels for buttons at bottom setTitle("Logan Express Bus"); buttonHolder = new JPanel(); // Create bus system object bSystem= new BusSystem(0.0, 0.0, 1.1); // Create and add the drawing area. Send bSystem as arg to get results drawArea = new BusDrawing(bSystem); drawArea.setSize(X, Y); conPane.add(drawArea, BorderLayout.CENTER); // Label for text field JLabel textFieldLabel = new JLabel("Enter bus time:"); buttonHolder.add(textFieldLabel); // Text field to enter time. timeField = new JTextField(4); buttonHolder.add(timeField); // Label for combo box JLabel textFieldLabel3 = new JLabel("Enter parking:"); buttonHolder.add(textFieldLabel3); // Combo box to select parking costs String[] parkingOptions = {"0.00", "2.00", "4.00", "6.00", "8.00", "10.00"}; parkingBox= new JComboBox(parkingOptions); buttonHolder.add(parkingBox); // Label for text field JLabel textFieldLabel2 = new JLabel("Enter objective:"); buttonHolder.add(textFieldLabel2); // Text field to enter objective weight. objectiveField = new JTextField(6); buttonHolder.add(objectiveField); // Create and add buttons calcButton = new JButton("Calculate"); buttonHolder.add(calcButton); calcButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Read the current value of the combo box String parkingString = (String)parkingBox.getSelectedItem(); double parking= Double.parseDouble(parkingString); parking= 100*parking; // Convert from dollars to cents // Read the current value of the text boxes double time = Double.parseDouble(timeField.getText().trim()); double obj = Double.parseDouble(objectiveField.getText().trim()); // Invoke the calculation method bSystem.setParam(time, parking, obj); bSystem.optimize(); // Generate vector of lines to draw on BusDrawing drawArea.busLines(); // Then repaint the canvas here. Drawing paintComponents will actually render drawArea.repaint(); } }); quitButton = new JButton("Quit"); buttonHolder.add(quitButton); quitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); conPane.add(buttonHolder, BorderLayout.SOUTH); } }