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.");
    }
  }
Example #2
0
  public void init() {
    this.setLayout(new BorderLayout());

    frame.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            System.out.println("MousePressed");
            pressed = true;
          }

          public void mouseReleased(MouseEvent e) {
            System.out.println("MouseReleased");
            released = true;
          }

          public void mouseClicked(MouseEvent e) {
            System.out.println("MouseClicked!!!!");
            clicked = true;
          }
        });
    frame.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            System.out.println("MouseDragged--" + e);
            dragged = true;
          }

          public void mouseMoved(MouseEvent e) {}
        });
  } // End  init()
Example #3
0
  public void go() {
    frame = new Frame();

    textField = new TextField();

    frame.add(textField, BorderLayout.SOUTH);

    frame.addMouseListener(this);
    frame.addMouseMotionListener(this);

    frame.addMouseListener(new MyMouselistener());
    frame.addMouseMotionListener(new MyMouselistener());

    frame.addWindowListener(this);

    frame.setSize(400, 400);

    frame.setVisible(true);
  }
 // test BUTTON1, 2 and 3 without any modifiers keys
 public static void testPlainButtons() {
   System.out.println("Testing buttons without modifiers.");
   f.addMouseListener(adapterTest1);
   for (int button : mouseButtons) {
     robot.mousePress(button);
     robot.delay(100);
     robot.mouseRelease(button);
   }
   robot.delay(1000);
   f.removeMouseListener(adapterTest1);
 }
 // test BUTTON1, 2 and 3 with ALT key
 public static void testButtonsWithAlt() {
   System.out.println("Testing buttons with ALT modifier.");
   f.addMouseListener(adapterTest4);
   for (int button : mouseButtons) {
     robot.keyPress(KeyEvent.VK_ALT);
     robot.mousePress(button);
     robot.delay(100);
     robot.mouseRelease(button);
     robot.keyRelease(KeyEvent.VK_ALT);
   }
   robot.delay(1000);
   f.removeMouseListener(adapterTest4);
 }
Example #6
0
  /** Creates new form VlcPlayer */
  public VlcPlayer() {
    vlcPlayerPanel = this;
    initComponents();
    positionSlider.setValue(0);
    mediaPlayerComponent = new MyEmbeddedMediaPlayerComponent();
    add(mediaPlayerComponent, BorderLayout.CENTER);

    MyMediaPlayerEventAdater mediaPlayerEventAdapter =
        new MyMediaPlayerEventAdater() {

          @Override
          public void finished(MediaPlayer mediaPlayer) {
            super.finished(mediaPlayer);
            stopButton.setEnabled(false);
            playButton.setEnabled(true);
            pauseButton.setEnabled(false);
            skipPreviousButton.setEnabled(false);
            skipNextButton.setEnabled(false);
            fullScreenButton.setEnabled(false);
            pauseButton.setText("暂停");
            pauseButton.setIcon(
                new javax.swing.ImageIcon(
                    getClass()
                        .getResource(
                            "/com/lorent/common/resource/images/media-playback-pause-8.png")));
          }

          @Override
          public void paused(MediaPlayer mediaPlayer) {
            super.paused(mediaPlayer);
            pauseButton.setText("继续");
            pauseButton.setIcon(
                new javax.swing.ImageIcon(
                    getClass()
                        .getResource(
                            "/com/lorent/common/resource/images/media-playback-start-8.png")));
          }

          @Override
          public void playing(MediaPlayer mediaPlayer) {
            super.playing(mediaPlayer);
            playButton.setEnabled(false);
            stopButton.setEnabled(true);
            pauseButton.setEnabled(true);
            skipPreviousButton.setEnabled(true);
            skipNextButton.setEnabled(true);
            fullScreenButton.setEnabled(true);
            pauseButton.setText("暂停");
            pauseButton.setIcon(
                new javax.swing.ImageIcon(
                    getClass()
                        .getResource(
                            "/com/lorent/common/resource/images/media-playback-pause-8.png")));
          }

          @Override
          public void stopped(MediaPlayer mediaPlayer) {
            super.stopped(mediaPlayer);
            stopButton.setEnabled(false);
            playButton.setEnabled(true);
            pauseButton.setEnabled(false);
            skipPreviousButton.setEnabled(false);
            skipNextButton.setEnabled(false);
            fullScreenButton.setEnabled(false);
            pauseButton.setText("暂停");
            pauseButton.setIcon(
                new javax.swing.ImageIcon(
                    getClass()
                        .getResource(
                            "/com/lorent/common/resource/images/media-playback-pause-8.png")));
          }

          @Override
          public void positionChanged(MediaPlayer mediaPlayer, float newPosition) {
            super.positionChanged(mediaPlayer, newPosition);

            final float temp = newPosition;

            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    int position = (int) (temp * 1000.0f);
                    //						log.info("positionChanged:  oldposition: "+mediaPlayerComponent
                    //								.getMediaPlayer().getPosition()+" newposition: "+temp);
                    positionSlider.setValue(position);
                    positionProgressBar.setValue(position);
                  }
                });
          }
        };

    mediaPlayerComponent.getMediaPlayer().addMediaPlayerEventListener(mediaPlayerEventAdapter);
    //		executorService.scheduleAtFixedRate(new UpdateRunnable(
    //				mediaPlayerComponent.getMediaPlayer()), 0L, 1L,
    //				TimeUnit.SECONDS);
    //		fullscreenWindow.setExtendedState(state)

    fullscreenWindow.setAlwaysOnTop(true);
    fullscreenWindow.setFocusable(true);
    fullscreenWindow.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseClicked(MouseEvent e) {
            log.info("fullscreenframe.mouseClicked");
          }
        });
    fullscreenWindow.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            mediaPlayerComponent.getMediaPlayer().setFullScreen(false);
          }
        });
    fullscreenWindow.addKeyListener(
        new KeyAdapter() {

          @Override
          public void keyPressed(KeyEvent e) {

            if (e.getID() == KeyEvent.KEY_PRESSED) {
              if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                if (fullscreenWindow.isVisible()) {
                  mediaPlayerComponent.getMediaPlayer().setFullScreen(false);
                }
              }
            }
          }
        });
    fullscreenWindow.setUndecorated(true);
    //		fullscreenDialog.setResizable(false);
    //
    //	GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(fullscreenframe);
  }