Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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 400 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
 
Ecumene (110 views)
2017-09-30 02:57:34

theagentd (147 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (241 views)
2017-08-02 12:19:43

cybrmynd (241 views)
2017-08-02 12:18:09

Sralse (254 views)
2017-07-25 17:13:48

Archive (874 views)
2017-04-27 17:45:51

buddyBro (1024 views)
2017-04-05 03:38:00

CopyableCougar4 (1578 views)
2017-03-24 15:39:42

theagentd (1374 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!