public void mouseMoved(MouseEvent ev) {
      JRootPane root = getRootPane();

      if (root.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }

      Window w = (Window) ev.getSource();

      Frame f = null;
      Dialog d = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else if (w instanceof Dialog) {
        d = (Dialog) w;
      }

      // Update the cursor
      int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY()));

      if (cursor != 0
          && ((f != null && (f.isResizable() && (f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0))
              || (d != null && d.isResizable()))) {
        w.setCursor(Cursor.getPredefinedCursor(cursor));
      } else {
        w.setCursor(lastCursor);
      }
    }
 /**
  * Uninstalls any state that <code>installClientDecorations</code> has installed.
  *
  * <p>NOTE: This may be called if you haven't installed client decorations yet (ie before <code>
  * installClientDecorations</code> has been invoked).
  */
 private void uninstallClientDecorations(JRootPane root) {
   uninstallBorder(root);
   uninstallWindowListeners(root);
   setTitlePane(root, null);
   uninstallLayout(root);
   // We have to revalidate/repaint root if the style is JRootPane.NONE
   // only. When we needs to call revalidate/repaint with other styles
   // the installClientDecorations is always called after this method
   // imediatly and it will cause the revalidate/repaint at the proper
   // time.
   int style = root.getWindowDecorationStyle();
   if (style == JRootPane.NONE) {
     root.repaint();
     root.revalidate();
   }
   // Reset the cursor, as we may have changed it to a resize cursor
   if (window != null) {
     window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   }
   window = null;
 }
 public void mouseExited(MouseEvent ev) {
   Window w = (Window) ev.getSource();
   w.setCursor(lastCursor);
 }
Beispiel #4
0
  public static void main(String[] args) {
    final Window window = new Window(g_szApplicationName);
    window.setIconImage(LoadIcon("/SimpleSoccer/icon1.png"));
    window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    buffer = new BufferedImage(WindowWidth, WindowHeight, BufferedImage.TYPE_INT_RGB);
    hdcBackBuffer = buffer.createGraphics();
    // these hold the dimensions of the client window area
    cxClient = buffer.getWidth();
    cyClient = buffer.getHeight();
    // seed random number generator
    common.misc.utils.setSeed(0);

    window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    // Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    window.setResizable(false);

    int y = center.y - window.getHeight() / 2;
    window.setLocation(center.x - window.getWidth() / 2, y >= 0 ? y : 0);
    Script1.MyMenuBar menu = Script1.createMenu(IDR_MENU1);
    window.setJMenuBar(menu);

    g_SoccerPitch = new SoccerPitch(cxClient, cyClient);

    CheckAllMenuItemsAppropriately(menu);

    createPanel();

    window.add(panel);
    window.pack();

    window.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            CppToJava.keyCache.released(e);
            switch (e.getKeyChar()) {
              case KeyEvent.VK_ESCAPE:
                {
                  System.exit(0);
                }
                break;
              case 'r':
              case 'R':
                {
                  SoccerPitchLock.lock();
                  g_SoccerPitch = null;
                  g_SoccerPitch = new SoccerPitch(cxClient, cyClient);
                  JMenuBar bar = Script1.createMenu(IDR_MENU1);
                  window.setJMenuBar(bar);
                  bar.revalidate();
                  SoccerPitchLock.unlock();
                }
                break;

              case 'p':
              case 'P':
                {
                  g_SoccerPitch.TogglePause();
                }
                break;
            } // end switch
          } // end switch        }

          @Override
          public void keyPressed(KeyEvent e) {
            CppToJava.keyCache.pressed(e);
          }
        });

    window.addComponentListener(
        new ComponentAdapter() {
          @Override // has the user resized the client area?
          public void componentResized(ComponentEvent e) {
            // if so we need to update our variables so that any drawing
            // we do using cxClient and cyClient is scaled accordingly
            cxClient = e.getComponent().getBounds().width;
            cyClient = e.getComponent().getBounds().height;
            // now to resize the backbuffer accordingly.
            buffer = new BufferedImage(cxClient, cyClient, BufferedImage.TYPE_INT_RGB);
            hdcBackBuffer = buffer.createGraphics();
          }
        });

    // make the window visible
    window.setVisible(true);

    // timer.SmoothUpdatesOn();

    // start the timer
    timer.Start();

    while (true) {
      // update
      if (timer.ReadyForNextFrame()) {
        SoccerPitchLock.lock();
        g_SoccerPitch.Update();
        SoccerPitchLock.unlock();
        // render
        // panel.revalidate();
        panel.repaint();

        try {
          // System.out.println(timer.TimeElapsed());
          Thread.sleep(2);
        } catch (InterruptedException ex) {
        }
      }
    } // end while
  }
Beispiel #5
0
 public void invisibleCursor() {
   Image curs;
   curs = new ImageIcon("Textures\\Cross.png").getImage();
   Window w = s.getFullScreenWindow();
   w.setCursor(w.getToolkit().createCustomCursor(curs, new Point(0, 0), "null"));
 }
 public static void setDefaultCursor(JComponent content) {
   final Window wnd = SwingUtilities.getWindowAncestor(content);
   if (wnd != null) {
     wnd.setCursor(Cursor.getDefaultCursor());
   }
 }