Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: matheus23 (posted 2013-01-03 14:45:59, viewed 242 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50  
package de.darwin.resourcedemo;

import java.awt.*;
import java.awt.image.*;

import darwin.resourcehandling.dependencies.ResourceHandlingModul;
import darwin.resourcehandling.dependencies.annotation.InjectResource;

import com.google.inject.*;
import javax.swing.JFrame;

/**
 * Hello world!
 *
 */
public class App extends JFrame {

    @InjectResource(file = "logo3.png")
    private ImageWrapper logo;

    public App() throws HeadlessException {
        super("Simple Demo");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setIgnoreRepaint(true);
        setBounds(0, 0, 800, 600);
        setResizable(false);

        setVisible(true);
        createBufferStrategy(2);
    }

    public void start() {
        BufferStrategy bs = getBufferStrategy();
        while (true) {
            Graphics2D drawGraphics = (Graphics2D) bs.getDrawGraphics();
            drawGraphics.clearRect(0, 0, 800, 600);

            BufferedImage i = logo.getImg();
            drawGraphics.drawImage(i, 400 - i.getWidth() / 2, 300 - i.getHeight() / 2, null);

            bs.show();
            Toolkit.getDefaultToolkit().sync();
        }
    }

    public static void main(String... args) {
        Guice.createInjector(Stage.DEVELOPMENT, new ResourceHandlingModul())
                .getInstance(App.class).start();
    }
}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30  
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.darwin.resourcedemo;

import java.awt.image.BufferedImage;

/**
 *
 * @author Daniel Heinrich <dannynullzwo@gmail.com>
 */
public class ImageWrapper {

    private BufferedImage img;

    public ImageWrapper(BufferedImage img) {
        this.img = img;
    }

    public BufferedImage getImg() {
        return img;
    }

    public void setImg(BufferedImage img) {
        if (img != null) {
            this.img = img;
        }
    }
}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54  
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.darwin.resourcedemo;

import java.awt.image.BufferedImage;
import java.io.IOException;

import darwin.annotations.ServiceProvider;
import darwin.resourcehandling.factory.*;
import darwin.resourcehandling.handle.ResourceHandle;

import javax.imageio.ImageIO;

/**
 *
 * @author Daniel Heinrich <dannynullzwo@gmail.com>
 */
@ServiceProvider(ResourceFromHandleProvider.class)
public class ImageLoader extends ResourceFromHandleProvider<ImageWrapper> implements ResourceFromHandle<ImageWrapper> {

    public ImageLoader() {
        super(ImageWrapper.class);
    }

    @Override
    public ImageWrapper create(ResourceHandle handle) throws IOException {
        return new ImageWrapper(createImage(handle));
    }
    
    private BufferedImage createImage(ResourceHandle handle) throws IOException
    {
        return ImageIO.read(handle.getStream());
    }

    @Override
    public void update(ResourceHandle changed, ImageWrapper wrapper) {
        try {
            wrapper.setImg(createImage(changed));
        } catch (IOException ex) {
        }
    }

    @Override
    public ImageWrapper getFallBack() {
        return new ImageWrapper(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB));
    }

    @Override
    public ResourceFromHandle<ImageWrapper> get(String[] options) {
        return new ImageLoader();
    }
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (51 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!