Advertisement
SforzandoCF

sh

Apr 8th, 2024 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package lx01.projects.stoneagesurvivalstuff;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Image;
  5. import javax.swing.JFrame;
  6. import javax.imageio.ImageIO;
  7.  
  8. public class StoneAgeSurvivalStuff {
  9.     public static void main (String[] args) {
  10.         JFrame window = new JFrame("Stone Age Survival Stuff");
  11.         try {
  12.             window.setIconImage(ImageIO.read(SASSAssets.getAssetStream("assets/textures/base/Icon.png")));
  13.             Graphics graphics = window.getGraphics();
  14.             Image img = ImageIO.read(SASSAssets.getAssetStream("assets/textures/player/PlayerDown.png"));
  15.             window.setVisible(true);
  16.             graphics.drawImage(img, (int) (graphics.getClipBounds().getWidth() / 2) - (img.getWidth(window) / 2), (int) (graphics.getClipBounds().getHeight() / 2) - (img.getHeight(window) / 2), window);
  17.         } catch (Exception e) {
  18.             e.printStackTrace();
  19.         }
  20.     }
  21. }
  22.  
  23. //
  24.  
  25. package lx01.projects.stoneagesurvivalstuff;
  26.  
  27. import java.util.List;
  28. import java.util.jar.JarFile;
  29. import java.util.jar.JarEntry;
  30. import java.io.File;
  31. import java.io.InputStream;
  32.  
  33. public class SASSAssets {
  34.     public static byte[] getAsset (String path) {
  35.         try {
  36.             return getAssetStream(path).readAllBytes();
  37.         } catch (Exception e) {
  38.             e.printStackTrace();
  39.             return getAsset(path);
  40.         }
  41.     }
  42.    
  43.     public static InputStream getAssetStream (String path) {
  44.         try {
  45.             JarFile jar = new JarFile(new File(SASSAssets.class.getProtectionDomain().getCodeSource().getLocation().toURI()));
  46.             JarEntry[] entries = (JarEntry[]) jar.stream().toArray();
  47.             for (JarEntry entry : entries) if (entry.getName().endsWith(path)) return jar.getInputStream(entry);
  48.             throw new IllegalArgumentException("Path supplied does not point to anything.");
  49.         } catch (Exception e) {
  50.             e.printStackTrace();
  51.             return getAssetStream(path);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement