コード例 #1
0
  /**
   * Create a instance of this check entry and set the configuration entry that is used to setup
   * this class.
   *
   * @param usedEntry the entry used to setup this class, the entry needs to pass the check with the
   *     static method
   */
  @SuppressWarnings("nls")
  public NumberEntryAwt(final ConfigEntry usedEntry) {
    super(new BorderLayout(10, 0));

    if (!isUsableEntry(usedEntry)) {
      throw new IllegalArgumentException("ConfigEntry type illegal.");
    }
    entry = (NumberEntry) usedEntry;

    currentValue = entry.getValue();

    display = new Label(Integer.toString(currentValue));
    add(display, BorderLayout.EAST);

    final Scrollbar scroll = new Scrollbar();
    scroll.setOrientation(Scrollbar.HORIZONTAL);
    scroll.setValues(currentValue, 1, entry.getRange().getMin(), entry.getRange().getMax() + 1);
    scroll.addAdjustmentListener(new NumberEntryScrollListener(this));
    add(scroll, BorderLayout.CENTER);

    setMinimumSize(new Dimension(300, 10));
  }
コード例 #2
0
  public MokumFrame() {
    setTitle("Heuristieken 2014 - Mokum Airlines! - Group 4 \"De Vliegende Hollanders\"");
    setLayout(new BorderLayout());
    setSize(1024, 768);

    frame = this;

    Dienstregeling dienstregeling = maakDienstregeling();

    schaal = new Scrollbar();
    schaal.setMaximum(100);
    schaal.setMinimum(1);
    schaal.setOrientation(Scrollbar.HORIZONTAL);
    schaal.setValue(45);
    schaal.setPreferredSize(new Dimension(250, 20));
    redrawButton = new Button("Redraw!");
    left = new BasicArrowButton(BasicArrowButton.WEST);
    right = new BasicArrowButton(BasicArrowButton.EAST);

    traffic = new GlobalTraffic(dienstregeling);
    dienst = new DienstregelingCanvas(dienstregeling);

    schaal.addAdjustmentListener(
        new AdjustmentListener() {
          // Houdt bij of er aan de scrollbar gezet is of niet
          public void adjustmentValueChanged(AdjustmentEvent e) {
            double scaleFactor = (double) schaal.getValue() / 100;
            dienst.setScaleFactor(scaleFactor);
            frame.redraw(200);
          }
        });
    redrawButton.addActionListener(
        new ActionListener() {
          // Houdt bij of er op de knop gedrukt is
          public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == redrawButton) {
              Dienstregeling dienstregeling = maakDienstregeling();
              traffic.setDienstregeling(dienstregeling);
              dienst.setDienstregeling(dienstregeling);
              frame.redraw(200);
            }
          }
        });

    left.addActionListener(
        new ActionListener() {
          // Houdt bij of er op de knop gedrukt is
          public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == left) {
              int val = schaal.getValue();
              schaal.setValue(val - 1);
              double scaleFactor = (double) schaal.getValue() / 100;
              dienst.setScaleFactor(scaleFactor);
              frame.redraw(200);
            }
          }
        });

    right.addActionListener(
        new ActionListener() {
          // Houdt bij of er op de knop gedrukt is
          public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == right) {
              int val = schaal.getValue();
              schaal.setValue(val + 1);
              double scaleFactor = (double) schaal.getValue() / 100;
              dienst.setScaleFactor(scaleFactor);
              frame.redraw(200);
            }
          }
        });

    Panel buttonPane = new Panel();
    buttonPane.setLayout(new FlowLayout());
    buttonPane.add(left);
    buttonPane.add(schaal);
    buttonPane.add(right);
    buttonPane.add(redrawButton);

    buttonPane.setPreferredSize(new Dimension(1024, 40));

    this.add(buttonPane, BorderLayout.SOUTH);

    JPanel topPanel = new JPanel();
    topPanel.add(traffic, BorderLayout.CENTER);
    traffic.setLocation(frame.getWidth() / 2, 0);

    this.add(topPanel, BorderLayout.NORTH);
    this.add(dienst, BorderLayout.CENTER);

    // Exit the program when the window is closed
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Close the window when escape is pressed
    this.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            super.keyPressed(e);
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
              System.exit(0);
            }
          }
        });

    mouseX = 0;
    mouseY = 0;

    this.addMouseMotionListener(
        new MouseMotionAdapter() {

          @Override
          public void mouseMoved(MouseEvent e) {
            super.mouseMoved(e);
            mouseX = (e.getX());
            mouseY = (e.getY()) - 25; // offset the 25px top bar

            mouseposition.setText(String.format("Mouse: %d, %d", mouseX, mouseY));
          }
        });

    mouseposition = new JLabel("Mouse:");
    buttonPane.add(mouseposition);

    // Resize the window
    pack();

    setVisible(true);
    frame.redraw(200);
  }