// init also call init from superclass public void init() { super.init(); Window w = s.getFullScreenWindow(); w.setFocusTraversalKeysEnabled(false); // just be a tab button, not just jump to next form w.addKeyListener(this); mess = "Press escape to exit"; }
// init public void init() { super.init(); mouse = new Point(); center = new Point(); image = new Point(); centering = false; try { robot = new Robot(); recenterMouse(); mouse.x = center.x; mouse.y = center.y; } catch (Exception e) { System.out.println("Exception 1"); } Window w = s.getFullScreenWindow(); w.addMouseMotionListener(this); w.addKeyListener(this); bg = new ImageIcon("/Users/Ole/Desktop/undefined/images/bg.jpg").getImage(); }
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 }