示例#1
0
文件: LJ3MDApp.java 项目: eskilj/mvp
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == timer) {
      for (int i = 0; i < speed; i++) // integrate a few steps
      md.vv();
      repaint();
      return;
    }

    boolean adjCanvasScale = false;

    if (src == bTstat) md.thermostat = !md.thermostat;

    if (src == bPot) {
      md.ljPotential = !md.ljPotential;
      md.clearData();

      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    if (src == tTemp || src == bReset) {
      double kT = Double.parseDouble(tTemp.getText().trim());
      if (kT < 1e-8) {
        kT = 1e-8;
        tTemp.setText("  " + kT);
      }
      md.kT = kT;
      md.clearData();
    }

    if (src == tRho || src == bReset) {
      double rho = Double.parseDouble(tRho.getText().trim());
      if (rho < 1e-3) {
        rho = 1e-3;
        tRho.setText("   " + rho);
      }
      if (rho > 1.2) {
        rho = 1.2;
        tRho.setText("   " + rho);
      }
      md.setDensity(rho);
      md.clearData();
      adjCanvasScale = true;
    }

    if (src == tSpeed || src == bReset) {
      speed = Integer.parseInt(tSpeed.getText().trim());
      if (speed < 1) {
        speed = 1;
        tSpeed.setText("   " + speed);
      }
    }

    if (src == bRetime) md.clearData();

    if (src == bStart) {
      boolean on = bStart.isSelected();
      if (on) {
        timer.restart();
        bStart.setText("Pause");
      } else {
        timer.stop();
        bStart.setText("Resume");
      }
    }

    if (src == tNum) {
      int n = Integer.parseInt(tNum.getText().trim());
      if (n < 2) {
        n = 2;
        tNum.setText(" " + n);
      }
      md.N = n;
      md.init(md.rho);
      adjCanvasScale = true;
    }

    if (src == bReset) {
      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale);

    repaint();
  }
示例#2
0
  public void jbInit() throws Exception {
    this.setLayout(null);
    fContractPriceTextField.setFont(new java.awt.Font("Dialog", 1, 11));
    fContractPriceTextField.setDisabledTextColor(Color.black);
    fContractPriceTextField.setEditable(false);
    fContractPriceTextField.setHorizontalAlignment(SwingConstants.RIGHT);
    fContractPriceTextField.setBounds(new java.awt.Rectangle(285, 182, 55, 21));
    fContractVolumeTextField.setFont(new java.awt.Font("Dialog", 1, 11));
    fContractVolumeTextField.setDisabledTextColor(Color.black);
    fContractVolumeTextField.setEditable(false);
    fContractVolumeTextField.setHorizontalAlignment(SwingConstants.RIGHT);
    fContractVolumeTextField.setBounds(new java.awt.Rectangle(285, 238, 55, 21));
    fContractVolumeLabel.setText(fRb.getString("CONTRACT_VOLUME"));
    fContractVolumeLabel.setForeground(Color.black);
    fContractVolumeLabel.setBounds(new java.awt.Rectangle(272, 218, 99, 17));
    fContractPriceLabel.setBounds(new java.awt.Rectangle(272, 160, 92, 17));
    fContractPriceLabel.setText(fRb.getString("CONTRACT_PRICE"));
    fContractPriceLabel.setForeground(Color.black);

    fBoardGraph.setLayout(borderLayout1);
    fDay.setBounds(new java.awt.Rectangle(337, 87, 42, 21));
    fDayLabel.setText(fRb.getString("DAY") + ":");
    fDayLabel.setForeground(Color.black);
    fDayLabel.setBounds(new java.awt.Rectangle(267, 89, 67, 17));
    fBoardLabel.setText(fRb.getString("SESSION") + ":");
    fBoardLabel.setForeground(Color.black);
    fBoardLabel.setBounds(new java.awt.Rectangle(267, 121, 68, 17));
    fBoard.setBounds(new java.awt.Rectangle(337, 119, 42, 22));
    fPreviousBoardLabel.setFont(new java.awt.Font("Dialog", 1, 12));
    fPreviousBoardLabel.setText(fRb.getString("PREVIOUS_PRICING"));
    fPreviousBoardLabel.setForeground(Color.black);
    fPreviousBoardLabel.setBounds(new java.awt.Rectangle(85, 4, 99, 17));
    fXYToggleButton.setBorder(BorderFactory.createRaisedBevelBorder());
    fXYToggleButton.setText("Exchange X-Y");
    fXYToggleButton.setBounds(new java.awt.Rectangle(268, 43, 114, 25));
    fXYToggleButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fIsExchangeXY = fXYToggleButton.isSelected();
            fIsUpdated = true;
            gUpdate();
          }
        });

    this.setBorder(BorderFactory.createEtchedBorder());
    this.setBounds(new java.awt.Rectangle(325, 7, 387, 283));
    this.setLayout(null);
    fBoardGraph.setBorder(BorderFactory.createEtchedBorder());
    fBoardGraph.setBounds(new java.awt.Rectangle(5, 26, 257, 243));
    fBoardGraph.getGraph().add(new UGraphData(fSellName, fSellColor));
    fBoardGraph.getGraph().add(new UGraphData(fBuyName, fBuyColor));
    fBoardGraph.setLeftMargin(60);
    this.add(fBoardGraph, null);
    this.add(fContractVolumeTextField, null);
    this.add(fContractVolumeLabel, null);
    this.add(fContractPriceTextField, null);
    this.add(fContractPriceLabel, null);
    this.add(fBoardLabel, null);
    this.add(fDayLabel, null);
    this.add(fXYToggleButton, null);
    this.add(fPreviousBoardLabel, null);
    this.add(fDay, null);
    this.add(fBoard, null);
    fBoardGraph.setBackground(Color.white);
    fBoardGraph.setNumOfHorizontalLine(0);
    fBoardGraph.setNumOfVerticalLine(0);
    fBoardGraph.setFixedMaxX(1);
    fBoardGraph.setFixedMinX(0);
    fBoardGraph.setFixedMaxY(1);
    fBoardGraph.setFixedMinY(0);
    addComponentListener(
        new ComponentAdapter() {
          public void componentShown(ComponentEvent ce) {
            gUpdate();
          }
        });
  }