public static void main(String[] args) { GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice displayDevice = environment.getDefaultScreenDevice(); frame = new Frame(displayDevice.getDefaultConfiguration()); frame.setBackground(new Color(0xCC, 0xCC, 0xCC)); frame.setTitle("TestBug735Inv0AppletAWT"); try { Class<?> c = Thread.currentThread() .getContextClassLoader() .loadClass(Bug735Inv0AppletAWT.class.getName()); applet = (Bug735Inv0AppletAWT) c.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } frame.setLayout(null); frame.add(applet); frame.pack(); frame.setResizable(false); applet.init(); Insets insets = frame.getInsets(); int windowW = applet.width + insets.left + insets.right; int windowH = applet.height + insets.top + insets.bottom; frame.setSize(windowW, windowH); Rectangle screenRect = displayDevice.getDefaultConfiguration().getBounds(); frame.setLocation( screenRect.x + (screenRect.width - applet.width) / 2, screenRect.y + (screenRect.height - applet.height) / 2); int usableWindowH = windowH - insets.top - insets.bottom; applet.setBounds( (windowW - applet.width) / 2, insets.top + (usableWindowH - applet.height) / 2, applet.width, applet.height); // This allows to close the frame. frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); applet.initGL(); frame.setVisible(true); applet.start(); }
private void initGL() { GLProfile profile = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(profile); caps.setBackgroundOpaque(true); caps.setOnscreen(true); caps.setSampleBuffers(false); if (TOOLKIT == AWT) { awtCanvas = new GLCanvas(caps); awtCanvas.setBounds(0, 0, applet.width, applet.height); awtCanvas.setBackground(new Color(0xFFCCCCCC, true)); awtCanvas.setFocusable(true); applet.setLayout(new BorderLayout()); applet.add(awtCanvas, BorderLayout.CENTER); if (MANUAL_FRAME_HANDLING) { awtCanvas.setIgnoreRepaint(true); awtCanvas.setAutoSwapBufferMode(false); } } else if (TOOLKIT == NEWT) { newtWindow = GLWindow.create(caps); newtCanvas = new NewtCanvasAWT(newtWindow); newtCanvas.setBounds(0, 0, applet.width, applet.height); newtCanvas.setBackground(new Color(0xFFCCCCCC, true)); newtCanvas.setFocusable(true); applet.setLayout(new BorderLayout()); applet.add(newtCanvas, BorderLayout.CENTER); if (MANUAL_FRAME_HANDLING) { newtCanvas.setIgnoreRepaint(true); newtWindow.setAutoSwapBufferMode(false); } } }