Example #1
0
  public void btnChoose_actionPerformed() {
    //            java.awt.Rectangle r = dateField.getBounds();
    //            Point pOnScreen = dateField.getLocationOnScreen();
    java.awt.Rectangle r = Jtext.getBounds();
    Point pOnScreen = Jtext.getLocationOnScreen();

    Point result = new Point(pOnScreen.x, pOnScreen.y + r.height);
    Point powner = owner.getLocation();
    int offsetX = (pOnScreen.x + width) - (powner.x + owner.getWidth());
    int offsetY = (pOnScreen.y + r.height + height) - (powner.y + owner.getHeight());

    if (offsetX > 0) {
      result.x -= offsetX;
    }

    if (offsetY > 0) {
      result.y -= height + r.height;
    }

    javax.swing.JDialog dateFrame = new javax.swing.JDialog();
    dateFrame.setModal(false);
    dateFrame.setUndecorated(true);
    dateFrame.setLocation(result);
    dateFrame.setSize(width, height);

    dateFrame.addWindowListener(
        new WindowAdapter() {
          // 鍦ㄤ换鎰忕殑闈炴棩鏈熼�夋嫨鍖哄崟鍑伙紝鍒欐棩鏈熼�夋嫨缁勪欢灏嗗彉涓洪潪娲诲姩鐘舵�侊紝鑷姩閲婃斁璧勬簮銆�
          public void windowDeactivated(WindowEvent e) {
            javax.swing.JDialog f = (javax.swing.JDialog) e.getSource();
            f.dispose();
          }
        });
    DatePanel datePanel = new DatePanel(dateFrame, parten);
    dateFrame.getContentPane().setLayout(new BorderLayout());
    dateFrame.getContentPane().add(datePanel);
    dateFrame.setVisible(true);
  }
  void test() {

    robot.waitForIdle();

    if (!text.isFocusOwner()) {
      robot.mouseMove(text.getLocationOnScreen().x + 5, text.getLocationOnScreen().y + 5);
      robot.delay(100);
      robot.mousePress(MouseEvent.BUTTON1_MASK);
      robot.delay(100);
      robot.mouseRelease(MouseEvent.BUTTON1_MASK);

      int iter = 10;
      while (!text.isFocusOwner() && iter-- > 0) {
        robot.delay(200);
      }
      if (iter <= 0) {
        Sysout.println("Test: text field couldn't be focused!");
        return;
      }
    }

    robot.keyPress(KeyEvent.VK_A);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_A);

    robot.waitForIdle();

    String charA = text.getText();
    System.err.println("Test: character typed with VK_A: " + charA);

    robot.keyPress(KeyEvent.VK_BACK_SPACE);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_BACK_SPACE);

    robot.waitForIdle();

    if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
      robot.keyPress(KeyEvent.VK_CONTROL);
    }
    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_F);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_F);
    robot.keyRelease(KeyEvent.VK_ALT);
    if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
      robot.keyRelease(KeyEvent.VK_CONTROL);
    }

    robot.waitForIdle();

    String string = text.getText();

    robot.keyPress(KeyEvent.VK_I);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_I);

    robot.waitForIdle();

    Sysout.println("Test: character typed after mnemonic key press: " + text.getText());

    if (!text.getText().equals(string)) {
      throw new RuntimeException("Test failed!");
    }

    robot.keyPress(KeyEvent.VK_A);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_A);

    robot.waitForIdle();

    System.err.println("Test: chracter typed with VK_A: " + text.getText());

    if (!charA.equals(text.getText())) {
      throw new RuntimeException("Test failed!");
    }

    Sysout.println("Test passed.");
  }