Java 类java.awt.Canvas 实例源码

项目:Rummy    文件:AView.java   
/**
 * Initiates a new View instance.
 * 
 * @param title
 *            The title displayed on the frame.
 * @param width
 *            The width of the frame.
 * @param height
 *            The height of the frame.
 * @param manager
 *            The RenderManager of this View, managing render layers.
 */
public AView(String mTitle, int mWidth, int mHeight, RenderManager mManager) {
    super(0, 0, mWidth, mHeight);

    manager = mManager;
    title = mTitle;
    height = mHeight;
    width = mWidth;

    frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setSize(width, height);
    frame.setLocationRelativeTo(null);
    frame.setVisible(false);

    canvas = new Canvas();
    canvas.setPreferredSize(new Dimension(width, height));
    canvas.setMaximumSize(new Dimension(width, height));
    canvas.setMinimumSize(new Dimension(width, height));
    canvas.setFocusable(false);
    canvas.setBounds(0, 0, width, height);

    frame.add(canvas);

}
项目:jdk8u-jdk    文件:bug8032667.java   
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
项目:openjdk-jdk10    文件:KeyboardFocusManagerPeerImpl.java   
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
项目:openjdk-jdk10    文件:bug8032667.java   
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
项目:openjdk9    文件:KeyboardFocusManagerPeerImpl.java   
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
项目:openjdk9    文件:bug8032667.java   
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
项目:Caterwolor    文件:Deprecated.java   
public static void main(final String[] args) {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(WIDTH1, HEIGHT1);
    final JPanel pane = (JPanel) frame.getContentPane();
    final Canvas canvas = new Deprecated();
    frame.add(canvas);

    frame.setVisible(true);

    final InputMap iMap = pane.getInputMap();
    final ActionMap aMap = pane.getActionMap();
    iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0), "R");
    aMap.put("R", new AbstractAction() {
        private static final long   serialVersionUID    = 3205299646057459152L;

        @Override
        public void actionPerformed(final ActionEvent arg0) {
            frame.remove(canvas);
            frame.add(canvas);
        }
    });
}
项目:itext2    文件:BarcodeDatamatrix.java   
/**
 * Creates a <CODE>java.awt.Image</CODE>. A successful call to the method <CODE>generate()</CODE>
 * before calling this method is required.
 * @param foreground the color of the bars
 * @param background the color of the background
 * @return the image
 */    
public java.awt.Image createAwtImage(Color foreground, Color background) {
    if (image == null)
        return null;
    int f = foreground.getRGB();
    int g = background.getRGB();
    Canvas canvas = new Canvas();

    int w = width + 2 * ws;
    int h = height + 2 * ws;
    int pix[] = new int[w * h];
    int stride = (w + 7) / 8;
    int ptr = 0;
    for (int k = 0; k < h; ++k) {
        int p = k * stride;
        for (int j = 0; j < w; ++j) {
            int b = image[p + (j / 8)] & 0xff;
            b <<= j % 8;
            pix[ptr++] = (b & 0x80) == 0 ? g : f;
        }
    }
    java.awt.Image img = canvas.createImage(new MemoryImageSource(w, h, pix, 0, w));
    return img;
}
项目:PhET    文件:JMEModule.java   
public JMEModule( Frame parentFrame, Function1<Frame, PhetJMEApplication> applicationFactory ) {
    super( JMECanvasFactory.createCanvas( parentFrame, applicationFactory ) );

    // gets what we created in the super-call
    canvas = (Canvas) getContent();

    // stores the created application statically, so we need to retrieve this
    app = JMEUtils.getApplication();

    addListener( new Listener() {
        public void activated() {
            app.startCanvas();
        }

        public void deactivated() {
        }
    } );

    // listen to resize events on our canvas, so that we can update our layout
    canvas.addComponentListener( new ComponentAdapter() {
        @Override public void componentResized( ComponentEvent e ) {
            app.onResize( canvas.getSize() );
        }
    } );
}
项目:PhET    文件:GameApplet.java   
/**
 * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
 * in another thread. It will also stop the game loop and destroy the display on canvas removal when
 * applet is destroyed.
 */
public void init() {
    setLayout(new BorderLayout());
    try {
        display_parent = new Canvas() {
            public void addNotify() {
                super.addNotify();
                startLWJGL();
            }
            public void removeNotify() {
                stopLWJGL();
                super.removeNotify();
            }
        };
        display_parent.setSize(getWidth(),getHeight());
        add(display_parent);
        display_parent.setFocusable(true);
        display_parent.requestFocus();
        display_parent.setIgnoreRepaint(true);
        setVisible(true);
    } catch (Exception e) {
        System.err.println(e);
        throw new RuntimeException("Unable to create display");
    }
}
项目:PhET    文件:AWTSurfaceLock.java   
private boolean privilegedLockAndInitHandle(final Canvas component) throws LWJGLException {
    // Workaround for Sun JDK bug 4796548 which still exists in java for OS X
    // We need to elevate privileges because of an AWT bug. Please see
    // http://192.18.37.44/forums/index.php?topic=10572 for a discussion.
    // It is only needed on first call, so we avoid it on all subsequent calls
    // due to performance..

    if (firstLockSucceeded)
        return lockAndInitHandle(lock_buffer, component);
    else
        try {
            firstLockSucceeded = AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
                public Boolean run() throws LWJGLException {
                    return lockAndInitHandle(lock_buffer, component);
                }
            });
            return firstLockSucceeded;
        } catch (PrivilegedActionException e) {
            throw (LWJGLException) e.getException();
        }
}
项目:PhET    文件:MacOSXCanvasPeerInfo.java   
protected void initHandle(Canvas component) throws LWJGLException {
    boolean forceCALayer = true;
    String javaVersion = System.getProperty("java.version");

    if (javaVersion.startsWith("1.5") || javaVersion.startsWith("1.6")) {
        // On Java 7 and newer CALayer mode is the only way to use OpenGL with AWT
        // therefore force it on all JVM's except for the older Java 5 and Java 6
        // where the older cocoaViewRef NSView method maybe be available.
        forceCALayer = false;
    }

    Insets insets = getInsets(component);

    int top = insets != null ? insets.top : 0;
    int left = insets != null ? insets.left : 0;

    window_handle = nInitHandle(awt_surface.lockAndGetHandle(component), getHandle(), window_handle, forceCALayer, component.getX()-left, component.getY()-top);

    if (javaVersion.startsWith("1.7")) {
        // fix for CALayer position not covering Canvas due to a Java 7 bug
        // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7172187
        addComponentListener(component);
    }
}
项目:PhET    文件:GearsApplet.java   
/**
 * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
 * in another thread. It will also stop the game loop and destroy the display on canvas removal when
 * applet is destroyed.
 */
public void init() {
    setLayout(new BorderLayout());
    try {
        display_parent = new Canvas() {
            public void addNotify() {
                super.addNotify();
                startLWJGL();
            }
            public void removeNotify() {
                stopLWJGL();
                super.removeNotify();
            }
        };
        display_parent.setSize(getWidth(),getHeight());
        add(display_parent);
        display_parent.setFocusable(true);
        display_parent.requestFocus();
        display_parent.setIgnoreRepaint(true);
        //setResizable(true);
        setVisible(true);
    } catch (Exception e) {
        System.err.println(e);
        throw new RuntimeException("Unable to create display");
    }
}
项目:jdk8u_jdk    文件:bug8032667.java   
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
项目:lookaside_java-1.8.0-openjdk    文件:bug8032667.java   
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
项目:LuoYing    文件:TestSwing2.java   
public Canvas createCanvas() {
    String appClass = TestEditor.class.getName();
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    settings.setFrameRate(30);

    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
        app.setPauseOnLostFocus(false);
        app.setSettings(settings);
        app.createCanvas();
        app.startCanvas();

        JmeCanvasContext context = (JmeCanvasContext) app.getContext();
        Canvas canvas = context.getCanvas();
        canvas.setSize(settings.getWidth(), settings.getHeight());

        return canvas;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        ex.printStackTrace();
    }
    return null;
}
项目:LuoYing    文件:SwingUtils.java   
public static Canvas createCanvas() {
    String appClass = TestEditor.class.getName();
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    settings.setFrameRate(60);

    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        LegacyApplication app = clazz.newInstance();
        app.setPauseOnLostFocus(false);
        app.setSettings(settings);
        app.createCanvas();
        app.startCanvas();

        JmeCanvasContext context = (JmeCanvasContext) app.getContext();
        Canvas canvas = context.getCanvas();
        canvas.setSize(settings.getWidth(), settings.getHeight());

        return canvas;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        ex.printStackTrace();
    }

    return null;
}
项目:Game-Needs-A-Name    文件:Display.java   
private void createDisplay(){
    frame = new JFrame(title);
    frame.setSize(width, height);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    canvas = new Canvas();
    canvas.setPreferredSize(new Dimension(width, height));
    canvas.setMaximumSize(new Dimension(width, height));
    canvas.setMinimumSize(new Dimension(width, height));

    frame.add(canvas);
    frame.pack();
}
项目:hi    文件:Game.java   
public static void show(int width, int height) {
    frame = new JFrame();
    frame.setTitle("Raycasting test #3 - ceil and floor");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(width, height);
    frame.setLocationRelativeTo(null);
    frame.add(canvas = new Canvas());
    frame.setVisible(true);

    canvas.requestFocus();
    canvas.addKeyListener(new KeyHandler());
    canvas.createBufferStrategy(2);
    canvasBufferStrategy = canvas.getBufferStrategy();

    init();

    new Thread(new MainLoop()).start();
}
项目:Side-Quest-City    文件:Window.java   
public Window(KTech gc) {
    image = new BufferedImage(gc.getWidth(), gc.getHeight(), BufferedImage.TYPE_INT_RGB); //Passes through the width and height

    canvas = new Canvas();
    Dimension s = new Dimension((int)(gc.getWidth() * gc.getScale()), (int)(gc.getHeight() * gc.getScale()));
    canvas.setPreferredSize(s);
    canvas.setMaximumSize(s);
    canvas.setPreferredSize(s);

    //Setting up the JFrame

    frame = new JFrame(gc.getTitle());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(canvas, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setVisible(true);

    canvas.createBufferStrategy(1);
    bs = canvas.getBufferStrategy();
    g = bs.getDrawGraphics();
}
项目:uosl    文件:GameView.java   
public GameView(MainController mainController) {
    this.mainController = mainController;
    this.glCanvas = new Canvas();
    this.game = mainController.getGameState();
    this.art = SLData.get().getArt();
    this.tiles = SLData.get().getTiles();
    this.inputGump = new InputGump();
    this.textLog = new TextLog();
    this.sysMessageEntry = new Object();
    this.pickBuffer = BufferUtils.createIntBuffer(1);
    this.pickList = new PickList();
    this.input = new InputManager();
    this.openGumps = new LinkedList<>();
    this.landRenderer = new LandRenderer();
    this.staticRenderer = new StaticRenderer();

    setLayout(new BorderLayout());
    glCanvas.enableInputMethods(true);
    add(glCanvas, BorderLayout.CENTER);

    glCanvas.addMouseListener(input);
    glCanvas.addMouseMotionListener(input);
    glCanvas.addKeyListener(input);

    projection = new Transform();
}
项目:pegasia    文件:RSLoader.java   
private static RSGraphics hookCanvas(RSClient client, Canvas gameCanvas, Collection<Class<?>> classList) throws ReflectiveOperationException {
    RSGraphics graphics = new RSGraphics(client, gameCanvas);
    boolean hooked = false;

    // Attempt to find any references to the game's internal canvas
    // and hook it with the custom canvas       
    for (Class<?> c: classList)
        for (Field f: c.getDeclaredFields())
            if (Modifier.isStatic(f.getModifiers()) && Canvas.class.isAssignableFrom(f.getType()) ) {
                f.setAccessible(true);
                f.set(null, graphics.canvas);
                hooked = true;
            }

    // If the canvas could not be hooked, dispose our custom canvas
    if (!hooked)
        throw new NoSuchFieldException("Unable to find \"static java.awt.Canvas\" field.");

    return graphics;
}
项目:openwonderland    文件:Client3DSim.java   
public FakeMainFrame() {
    try {
        frame = new JFrame();
    } catch (HeadlessException he) {
        // ignore
        logger.log(Level.INFO, "Running in headless mode");
    }
    canvasPanel = new JPanel(new BorderLayout());
    canvas = new Canvas();

    canvasPanel.add(canvas, BorderLayout.CENTER);

    if (frame != null) {
        frame.setContentPane(canvasPanel);
    }
}
项目:openwonderland    文件:InputManager.java   
/** 
    * Initialize the input manager to receive input events from the given AWT canvas
    * and start the input manager running. The input manager will perform picks with the
    * given camera. This routine can only be called once. To subsequently change the 
    * camera, use <code>setCameraComponent</code>. To subsequently change the focus manager,
    * use <code>setFocusManager</code>.
    * @param canvas The AWT canvas which generates AWT user events.
    * @param cameraComp The mtgame camera component to use for picking operations.
    */
   public void initialize (Canvas canvas, CameraComponent cameraComp) {
if (this.canvas != null) {
    throw new IllegalStateException("initialize has already been called for this InputManager");
}
this.canvas = canvas;
inputPicker.setCanvas(canvas);

setCameraComponent(cameraComp);

canvas.addKeyListener(this);
canvas.addMouseListener(this);
canvas.addMouseMotionListener(this);
canvas.addMouseWheelListener(this);
canvas.addFocusListener(this);
       canvas.setDropTarget(new DropTarget(canvas, this));

logger.fine("Input System initialization complete.");
   }
项目:APCS_3rd_Hour_2015    文件:Display.java   
private void createDisplay()
{
    //Creates JFrame with constructor data
    frame = new JFrame(title);
    frame.setSize(width, height);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    //Creates a Canvas to draw the game on
    canvas = new Canvas();
    canvas.setBackground(Color.BLACK);
    canvas.setPreferredSize(new Dimension(width, height));
    canvas.setMaximumSize(new Dimension(width, height));
    canvas.setMinimumSize(new Dimension(width, height));
    canvas.setFocusable(false);

    //Adds canvas to JFram
    frame.add(canvas);
    frame.pack();
}
项目:HexGrid_JME    文件:HexGridModule.java   
@Override
    public void onContextGainFocus(SimpleApplication app, Canvas canvas) {
        add(canvas, BorderLayout.CENTER);
        this.app = app;
        app.getInputManager().addMapping(MouseInputEvent.MouseInputEventType.LMB.toString(), 
                new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        app.getInputManager().addMapping(MouseInputEvent.MouseInputEventType.RMB.toString(),
                new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
//        app.getInputManager().addMapping("Confirm", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
//        app.getInputManager().addMapping("Cancel", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));


//        app.getFlyByCamera().setEnabled(false);
        rtsCam.setCenter(camPos);
        app.getStateManager().attachAll(rtsCam, hexGridState, mouseSystem);
        if(!init) {
            for (HexGridPropertiesPan pan : propertiesPans) {
                pan.onMapLoaded();
            }
            init = true;
        }
        revalidate();
    }
项目:siteplan    文件:Preview.java   
private Container getPanel() {
    Dimension d3Dim = new Dimension (800, 600);

    AppSettings settings = new AppSettings(true);

    settings.setWidth(d3Dim.width);
    settings.setHeight(d3Dim.height);
    settings.setSamples(4);
    settings.setVSync(true);
    settings.setFrameRate(60);

    setSettings(settings);
    createCanvas();
    JmeCanvasContext ctx = (JmeCanvasContext) getContext();
    ctx.setSystemListener(this);

    Canvas canvas = ctx.getCanvas();
    canvas.setPreferredSize(d3Dim);

    JPanel panel = new JPanel(new BorderLayout());
    panel.add( canvas, BorderLayout.CENTER );

    return panel;
}
项目:totalboumboum    文件:LoopPanel.java   
/**
 * Starts displaying the game.
 */
public void start()
{   requestFocus();
    loop.setPanel(this);
    if(mode==0)
    {   int width = getPreferredSize().width;
        int height = getPreferredSize().height;
        image = createImage(width, height);
    }
    else if(mode==1)
        image = createVolatileImage();
    else if(mode==2)
    {   Canvas canvas = new Canvas();
        canvas.setPreferredSize(getPreferredSize());
        add(canvas);
        canvas.createBufferStrategy(2);
        bufferStrategy = canvas.getBufferStrategy();
    }
}
项目:infobip-open-jdk-8    文件:bug8032667.java   
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
项目:jdk8u-dev-jdk    文件:bug8032667.java   
@Override
public void init() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            final Image image1 = getImage(getCheckBox("Deselected", false));
            final Image image2 = getImage(getCheckBox("Selected", true));

            Canvas canvas = new Canvas() {

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);
                    g.drawImage(image2, 0, scaledHeight + 5,
                            scaledWidth, scaledHeight, this);
                }
            };

            getContentPane().add(canvas, BorderLayout.CENTER);
        }
    });
}
项目:tinyMediaManager    文件:MovieScraperSettingsPanel.java   
private ImageIcon getScaledIcon(ImageIcon original) {
  Canvas c = new Canvas();
  FontMetrics fm = c.getFontMetrics(new JPanel().getFont());

  int height = (int) (fm.getHeight() * 2f);
  int width = original.getIconWidth() / original.getIconHeight() * height;

  BufferedImage scaledImage;
  if (!scraper.isEnabled()) {
    scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
        Scalr.OP_GRAYSCALE);
  }
  else {
    scaledImage = Scalr.resize(ImageCache.createImage(original.getImage()), Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height,
        Scalr.OP_ANTIALIAS);
  }
  return new ImageIcon(scaledImage);
}
项目:APICloud-Studio    文件:CefBrowser_N.java   
/**
    * Create a new browser.
    */
protected void createBrowser(CefClientHandler clientHandler,
                             long windowHandle, 
                             String url, 
                             boolean transparent, 
                             Canvas canvas,
                             CefRequestContext context) {
    if (getNativeRef("CefBrowser") == 0 && !isPending_) {
        try {
            isPending_ = N_CreateBrowser(clientHandler, 
                                         windowHandle, 
                                         url,
                                         transparent, 
                                         canvas, 
                                         context);
        } catch (UnsatisfiedLinkError err) {
            err.printStackTrace();
        }
    }
}
项目:APICloud-Studio    文件:CefBrowser_N.java   
/**
  * Create a new browser as dev tools
  */
protected final void createDevTools(CefBrowser parent,
                                    CefClientHandler clientHandler, 
                                    long windowHandle,
                                    boolean transparent, 
                                    Canvas canvas) {
   if (getNativeRef("CefBrowser") == 0 && !isPending_) {
    try {
       isPending_ = N_CreateDevTools(parent,
                                     clientHandler,
                                     windowHandle,
                                     transparent,
                                     canvas);
    } catch (UnsatisfiedLinkError err) {
        err.printStackTrace();
    }
}
 }
项目:trashjam2017    文件:AppletGameContainer.java   
/**
 * @see java.applet.Applet#init()
 */
public void init() {
   removeAll();
   setLayout(new BorderLayout());
   setIgnoreRepaint(true);

   try {
      Game game = (Game) Class.forName(getParameter("game")).newInstance();

      container = new Container(game);
      canvas = new ContainerPanel(container);
      displayParent = new Canvas() {
         public final void addNotify() {
            super.addNotify();
            startLWJGL();
         }
         public final void removeNotify() {
            destroyLWJGL();
            super.removeNotify();
         }

      };

      displayParent.setSize(getWidth(), getHeight());
      add(displayParent);
      displayParent.setFocusable(true);
      displayParent.requestFocus();
      displayParent.setIgnoreRepaint(true);
      setVisible(true);
   } catch (Exception e) {
      Log.error(e);
      throw new RuntimeException("Unable to create game container");
   }
}
项目:SimpleRecurrentNetwork    文件:Unit.java   
public Unit(){
    getBestSize();

    net = new Net(new int[]{4,5,4}, true);
    graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");

    frame = new Frame();
    canvas = new Canvas();

    canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
    canvas.addKeyListener(new InputHandler());
    canvas.addMouseListener(new InputHandler());
    canvas.addMouseMotionListener(new InputHandler());

    frame.add(canvas);

    frame.pack();
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);

    frame.addWindowListener(new WindowAdapter(){
        @Override
        public void windowClosing(WindowEvent e){
            Test.quit(net);
        }
    });

    frame.setVisible(true);
    gc = canvas.getGraphicsConfiguration();
    vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);

}
项目:Progetto-C    文件:AppletGameContainer.java   
/**
 * @see java.applet.Applet#init()
 */
public void init() {
   removeAll();
   setLayout(new BorderLayout());
   setIgnoreRepaint(true);

   try {
      Game game = (Game) Class.forName(getParameter("game")).newInstance();

      container = new Container(game);
      canvas = new ContainerPanel(container);
      displayParent = new Canvas() {
         public final void addNotify() {
            super.addNotify();
            startLWJGL();
         }
         public final void removeNotify() {
            destroyLWJGL();
            super.removeNotify();
         }

      };

      displayParent.setSize(getWidth(), getHeight());
      add(displayParent);
      displayParent.setFocusable(true);
      displayParent.requestFocus();
      displayParent.setIgnoreRepaint(true);
      setVisible(true);
   } catch (Exception e) {
      Log.error(e);
      throw new RuntimeException("Unable to create game container");
   }
}
项目:rekit-game    文件:GameView.java   
/**
 * Constructor that creates a new window with a canvas and prepares all
 * required attributes.
 *
 * @param model
 *            the model
 */
GameView(Model model) {
    this.model = model;
    // Create window
    this.frame = new JFrame(GameConf.NAME + " (v." + GameConf.VERSION + ")");
    this.frame.setIconImage(ImageManagement.get(GameView.ICON_LOCATION));
    this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.frame.setResizable(false);
    this.frame.setSize(GameConf.PIXEL_W, GameConf.PIXEL_H);
    this.center(this.frame);
    this.frame.setLayout(new BorderLayout());

    // Create and position a canvas
    this.canvas = new Canvas();
    this.canvas.setPreferredSize(new Dimension(GameConf.PIXEL_W, GameConf.PIXEL_H));
    this.canvas.setIgnoreRepaint(true);
    this.frame.add(this.canvas, BorderLayout.CENTER);
    this.frame.pack();

    this.canvas.createBufferStrategy(2);
    this.bufferStrategy = this.canvas.getBufferStrategy();
    this.frame.setVisible(true);

    // Create Graphic context
    this.grid = new GameGridImpl();
}
项目:CGL    文件:Listener.java   
/**
 * Sets up the Listener
 * @param cnv   Canvas
 */
public static void setup(Canvas cnv){
    cnv.addKeyListener(new Listener());
    cnv.addMouseListener(new Listener());
    cnv.addMouseWheelListener(new Listener());
    cnv.addMouseMotionListener(new Listener());
}
项目:CGL    文件:Listener.java   
public static void init(Window frame2, Canvas cnv) {
    Listener.canvas = cnv;
    Listener.framec = frame2;
    setup(cnv);
    setup(frame2);

    try {
        robot = new Robot();
    } catch (AWTException e) {
        e.printStackTrace();
    }
}
项目:NormalFeedForwardNeuralNet    文件:Unit.java   
public Unit(){
    getBestSize();

    net = new Net(new int[]{2,5,2});
    graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");

    frame = new Frame();
    canvas = new Canvas();

    canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
    canvas.addKeyListener(new InputHandler());
    canvas.addMouseListener(new InputHandler());
    canvas.addMouseMotionListener(new InputHandler());

    frame.add(canvas);

    frame.pack();
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);

    frame.addWindowListener(new WindowAdapter(){
        @Override
        public void windowClosing(WindowEvent e){
            Test.quit(net);
        }
    });

    frame.setVisible(true);
    gc = canvas.getGraphicsConfiguration();
    vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);

}