Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lx01.projects.stoneagesurvivalstuff;
- import java.awt.Graphics;
- import java.awt.Image;
- import javax.swing.JFrame;
- import javax.imageio.ImageIO;
- public class StoneAgeSurvivalStuff {
- public static void main (String[] args) {
- JFrame window = new JFrame("Stone Age Survival Stuff");
- try {
- window.setIconImage(ImageIO.read(SASSAssets.getAssetStream("assets/textures/base/Icon.png")));
- Graphics graphics = window.getGraphics();
- Image img = ImageIO.read(SASSAssets.getAssetStream("assets/textures/player/PlayerDown.png"));
- window.setVisible(true);
- graphics.drawImage(img, (int) (graphics.getClipBounds().getWidth() / 2) - (img.getWidth(window) / 2), (int) (graphics.getClipBounds().getHeight() / 2) - (img.getHeight(window) / 2), window);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- //
- package lx01.projects.stoneagesurvivalstuff;
- import java.util.List;
- import java.util.jar.JarFile;
- import java.util.jar.JarEntry;
- import java.io.File;
- import java.io.InputStream;
- public class SASSAssets {
- public static byte[] getAsset (String path) {
- try {
- return getAssetStream(path).readAllBytes();
- } catch (Exception e) {
- e.printStackTrace();
- return getAsset(path);
- }
- }
- public static InputStream getAssetStream (String path) {
- try {
- JarFile jar = new JarFile(new File(SASSAssets.class.getProtectionDomain().getCodeSource().getLocation().toURI()));
- JarEntry[] entries = (JarEntry[]) jar.stream().toArray();
- for (JarEntry entry : entries) if (entry.getName().endsWith(path)) return jar.getInputStream(entry);
- throw new IllegalArgumentException("Path supplied does not point to anything.");
- } catch (Exception e) {
- e.printStackTrace();
- return getAssetStream(path);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement