Exemple #1
0
  /**
   * The ControlPanel creates all buttons that interact with the main factory simulation.
   *
   * @param mainInterface Provides reference to parent JFrame
   */
  public ControlPanel(MainInterface mainInterface) {
    parentFrame = mainInterface;
    setPreferredSize(new Dimension(280, 669));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    /* Initialize audio
    try {
    	audioPlayer = new AudioPlayer(new File("assets/sounds/pureimagination.wav"));
    	audio.start();
    }
    catch (Exception e){
    	System.out.println("ERROR: Audio cannot be played");
    } */

    // Initialisation of top two buttons, namely jbtnStart and jbtnStop
    jbtnStart = new JButton("Start");
    jbtnStart.setVerticalTextPosition(AbstractButton.CENTER);
    jbtnStart.setHorizontalTextPosition(AbstractButton.LEADING);
    jbtnStart.setActionCommand("startsim");
    jbtnStart.addActionListener(this);
    jbtnStart.setFocusPainted(false);
    jbtnStart.setEnabled(true);

    jbtnStop = new JButton("Stop");
    jbtnStop.setVerticalTextPosition(AbstractButton.CENTER);
    jbtnStop.setHorizontalTextPosition(AbstractButton.TRAILING);
    jbtnStop.setActionCommand("pausesim");
    jbtnStop.addActionListener(this);
    jbtnStop.setFocusPainted(false);
    jbtnStop.setEnabled(false);

    // Initialisation of the vibration speed slider.
    jslVibration = new JSlider(JSlider.HORIZONTAL, vibrMIN, vibrMAX, vibrINI);
    jslVibration.addChangeListener(new VibrationListener());
    jslVibration.setMajorTickSpacing(5);
    jslVibration.setMinorTickSpacing(1);
    jslVibration.setPaintTicks(true);
    jslVibration.setPaintLabels(true);
    jslVibration.setFont(new Font("Dialog", Font.PLAIN, 10));
    jslVibration.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEmptyBorder(),
            "CONVEYOR VIBRATION SPEED",
            TitledBorder.CENTER,
            TitledBorder.TOP,
            new Font("Dialog", Font.PLAIN, 9)));

    // Initialisation of the frame rate slider.
    jslFrameRate = new JSlider(JSlider.HORIZONTAL, frameMIN, frameMAX, frameINI);
    jslFrameRate.addChangeListener(new FrameRateListener());
    jslFrameRate.setMajorTickSpacing(20);
    jslFrameRate.setMinorTickSpacing(4);
    jslFrameRate.setPaintTicks(true);
    jslFrameRate.setPaintLabels(true);
    jslFrameRate.setFont(new Font("Dialog", Font.PLAIN, 10));
    jslFrameRate.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEmptyBorder(),
            "FRAME RATE",
            TitledBorder.CENTER,
            TitledBorder.TOP,
            new Font("Dialog", Font.PLAIN, 9)));

    // Initialisation of the KitSelection and ConsolePanel sub-panels.
    kitSelection = new KitSelection(parentFrame);
    consolePanel = new ConsolePanel(parentFrame);

    // Initialisation of the layout for the start and stop buttons.
    JPanel startStop = new JPanel();
    startStop.setLayout(new FlowLayout(FlowLayout.CENTER));
    startStop.setPreferredSize(new Dimension(200, 30));
    startStop.add(jbtnStart);
    startStop.add(jbtnStop);

    // Initialisation of the combination layout for the buttons and sliders.
    JPanel options = new JPanel();
    options.setLayout(new BoxLayout(options, BoxLayout.Y_AXIS));
    options.setPreferredSize(new Dimension(200, 178));
    options.add(startStop);
    options.add(jslVibration);
    options.add(jslFrameRate);

    // Aesthetic settings and adding all sub-panels to the main control panel.
    options.setBorder(BorderFactory.createTitledBorder("Options"));
    add(options);
    add(kitSelection);
    add(consolePanel);

    // Set a default vibration speed.
    UserData.setVibrationSpeed(this, 2);
  }
Exemple #2
0
 @Override
 public void stateChanged(ChangeEvent e) {
   JSlider source = (JSlider) e.getSource();
   UserData.setVibrationSpeed(outer, (int) source.getValue());
 }