⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windowedmode.java

📁 一个java的免费游戏引擎,里面有文档,和例子
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

package com.golden.gamedev.engine.graphics;

import com.golden.gamedev.engine.BaseGraphics;
import com.golden.gamedev.util.ImageUtil;
import java.awt.*;
import java.awt.image.BufferStrategy;
import java.awt.image.VolatileImage;
import java.io.PrintStream;

// Referenced classes of package com.golden.gamedev.engine.graphics:
//            WindowExitListener

public class WindowedMode
    implements BaseGraphics
{

    public static final GraphicsDevice DEVICE;
    public static final GraphicsConfiguration CONFIG;
    private Frame d;
    private Canvas e;
    private Dimension f;
    private VolatileImage g;
    private BufferStrategy h;
    private Graphics2D i;
    static Class a;

    public WindowedMode(Dimension dimension, boolean flag)
    {
        f = dimension;
        d = new Frame("Golden T Game Engine", CONFIG);
        try
        {
            d.setIconImage(ImageUtil.getImage((a != null ? a : (a = a("com.golden.gamedev.engine.graphics.WindowedMode"))).getResource("Icon.png")));
        }
        catch(Exception _ex) { }
        d.addWindowListener(WindowExitListener.getInstance());
        d.setResizable(false);
        d.setIgnoreRepaint(true);
        e = new Canvas(CONFIG);
        e.setIgnoreRepaint(true);
        e.setSize(f);
        d.setVisible(true);
        Insets insets = d.getInsets();
        d.setVisible(false);
        d.setSize(f.width + insets.left + insets.right, f.height + insets.top + insets.bottom);
        d.add(e);
        d.pack();
        d.setLayout(null);
        d.setLocationRelativeTo(null);
        d.setVisible(true);
        if(flag)
            c();
        else
            d();
        e.requestFocus();
    }

    private void c()
    {
        e.createBufferStrategy(2);
        while(h == null) 
            try
            {
                h = e.getBufferStrategy();
            }
            catch(Exception _ex) { }
        do
            try
            {
                getBackBuffer();
                return;
            }
            catch(Exception _ex) { }
        while(true);
    }

    private void d()
    {
        if(g != null)
        {
            g.flush();
            g = null;
        }
        g = CONFIG.createCompatibleVolatileImage(f.width, f.height);
    }

    public Graphics2D getBackBuffer()
    {
        if(i == null)
            if(h == null)
            {
                if(g.validate(CONFIG) == 2)
                    d();
                i = g.createGraphics();
            } else
            {
                i = (Graphics2D)h.getDrawGraphics();
            }
        return i;
    }

    public boolean flip()
    {
        i.dispose();
        i = null;
        if(h == null)
        {
            e.getGraphics().drawImage(g, 0, 0, null);
            Toolkit.getDefaultToolkit().sync();
            return !g.contentsLost();
        }
        h.show();
        Toolkit.getDefaultToolkit().sync();
        return !h.contentsLost();
    }

    public void cleanup()
    {
        try
        {
            Thread.sleep(200L);
        }
        catch(InterruptedException _ex) { }
        try
        {
            if(d != null)
                d.dispose();
            return;
        }
        catch(Exception exception)
        {
            System.err.println("ERROR: Shutting down graphics context " + exception);
        }
        System.exit(-1);
    }

    public Dimension getSize()
    {
        return f;
    }

    public Component getComponent()
    {
        return e;
    }

    public Frame getFrame()
    {
        return d;
    }

    public boolean isBufferStrategy()
    {
        return h != null;
    }

    public String getGraphicsDescription()
    {
        return "Windowed Mode [" + getSize().width + "x" + getSize().height + "]" + (h == null ? "" : " with BufferStrategy");
    }

    public void setWindowTitle(String s)
    {
        d.setTitle(s);
    }

    public String getWindowTitle()
    {
        return d.getTitle();
    }

    public void setWindowIcon(Image image)
    {
        try
        {
            d.setIconImage(image);
            return;
        }
        catch(Exception _ex)
        {
            return;
        }
    }

    public Image getWindowIcon()
    {
        return d.getIconImage();
    }

    static Class a(String s)
    {
        return Class.forName(s);
        ClassNotFoundException classnotfoundexception;
        classnotfoundexception;
        throw new NoClassDefFoundError(classnotfoundexception.getMessage());
    }

    static 
    {
        DEVICE = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        CONFIG = DEVICE.getDefaultConfiguration();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -