Example usage for java.awt Canvas setBackground

List of usage examples for java.awt Canvas setBackground

Introduction

In this page you can find the example usage for java.awt Canvas setBackground.

Prototype

public void setBackground(Color c) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:net.wurstclient.hooks.FrameHook.java

public static void createFrame(DefaultResourcePack mcDefaultResourcePack, Logger logger) throws LWJGLException {
    // check if frame should be created
    if (!isAutoMaximize() && !WurstBot.isEnabled())
        return;// w ww.  j a va 2s.c o m

    // create frame
    frame = new JFrame("Minecraft 1.8");

    // add LWJGL
    Canvas canvas = new Canvas();
    canvas.setBackground(new Color(16, 16, 16));
    Display.setParent(canvas);
    Minecraft mc = Minecraft.getMinecraft();
    canvas.setSize(mc.displayWidth, mc.displayHeight);
    frame.add(canvas);

    // configure frame
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);

    // add icons
    InputStream icon16 = null;
    InputStream icon32 = null;
    try {
        icon16 = mcDefaultResourcePack.func_152780_c(new ResourceLocation("icons/icon_16x16.png"));
        icon32 = mcDefaultResourcePack.func_152780_c(new ResourceLocation("icons/icon_32x32.png"));
        ArrayList<BufferedImage> icons = new ArrayList<>();
        icons.add(ImageIO.read(icon16));
        icons.add(ImageIO.read(icon32));
        frame.setIconImages(icons);
    } catch (Exception e) {
        logger.error("Couldn't set icon", e);
    } finally {
        IOUtils.closeQuietly(icon16);
        IOUtils.closeQuietly(icon32);
    }

    // show frame
    if (!WurstBot.isEnabled())
        frame.setVisible(true);
}