public static void main(String s[]) {
    initParams(s);
    initAdapters();
    f = new Frame();
    final int[] modifiers = {InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK};
    final String[] modifierNames = {"InputEvent.SHIFT_MASK", "InputEvent.CTRL_MASK"};
    f.setLayout(new FlowLayout());
    f.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("WHEEL " + e);
          }
        });
    f.setSize(300, 300);
    f.setVisible(true);

    try {
      robot = new Robot();
      robot.delay(500);
      robot.mouseMove(
          f.getLocationOnScreen().x + f.getWidth() / 2,
          f.getLocationOnScreen().y + f.getHeight() / 2);
      if (autorun) {
        // testing buttons 1, 2, 3 only
        testPlainButtons();
        robot.delay(500);

        // testing buttons 1, 2, 3 with SHIFT, CTRL, ALT keyboard modifiers
        testButtonsWithShift();
        robot.delay(500);

        testButtonsWithControl();
        robot.delay(500);

        testButtonsWithAlt();
        robot.delay(500);
      } else {
        switch (testModifier) {
          case SHIFT:
            f.addMouseListener(adapterTest2);
            break;
          case CTRL:
            f.addMouseListener(adapterTest3);
            break;
          case ALT:
            f.addMouseListener(adapterTest4);
            break;
          default: // NONE inclusive
            f.addMouseListener(adapterTest1);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException("Test failed.");
    }
  }
Esempio n. 2
0
 private void centerOnScreen(Frame frame) {
   Point point = frame.getLocationOnScreen();
   Dimension dimension = frame.getSize();
   Dimension dimension1 = getSize();
   point.x += (dimension.width - dimension1.width) / 2;
   point.y += (dimension.height - dimension1.height) / 2;
   Dimension dimension2 = Toolkit.getDefaultToolkit().getScreenSize();
   if (point.x < 0
       || point.y < 0
       || point.x + dimension1.width > dimension2.width
       || point.y + dimension1.height > dimension2.height) {
     point.x = (dimension2.width - dimension1.width) / 2;
     point.y = (dimension2.height - dimension1.height) / 2;
   }
   setLocation(point.x, point.y);
 }