Advertisement
Guest User

FTB Borderless Window Source Code

a guest
Jul 18th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.92 KB | None | 0 0
  1. /*
  2.  * Copyright(C) Thepattybeast 2015
  3.  * */
  4. package net.minecraft.launchwrapper;
  5.  
  6. import java.awt.Canvas;
  7. import java.awt.GraphicsEnvironment;
  8. import java.awt.Rectangle;
  9. import java.io.File;
  10. import java.io.IOException;
  11. import java.net.MalformedURLException;
  12. import java.net.URISyntaxException;
  13. import java.net.URL;
  14. import java.net.URLClassLoader;
  15.  
  16. import javax.swing.JFrame;
  17. import javax.swing.JOptionPane;
  18.  
  19. public class Launch {
  20.  
  21.     public static void main(String[] args) throws InterruptedException, IOException{
  22.         System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");//Activate borderless window
  23.         URL[] cp = ((URLClassLoader)Launch.class.getClassLoader()).getURLs();//Get the classpath(-cp) the program was launched with
  24.         String jarName = getJar().getName();
  25.         //scan for the classpath entry that is this jar file and replace it with the classpatth entry of the actual realauncher
  26.         for(int i = 0; i < cp.length; i++){
  27.             System.out.println(cp[i].getPath() + " <-- " + jarName);
  28.             if(cp[i].getPath().contains(jarName))
  29.                 System.out.println("OK");
  30.                 try {
  31.                     cp[i] = new URL("file:///"+cp[i].getPath().replace(jarName, "launchwrapper.jar"));
  32.                 } catch (MalformedURLException e) {
  33.                     e.printStackTrace();
  34.                 }
  35.         }
  36.        
  37.         final URLClassLoader loader = new URLClassLoader(cp, null);
  38.         try{
  39.             //the only way to get centered borderless is to remove the borders completely by attaching the LWJGL Display to a canvas
  40.             JFrame MCWindow = new JFrame("MC Window");
  41.             //Get the size of the default display
  42.             //the LWJGL Display will always be at 0, 0 regardless JFrame position
  43.             Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
  44.             MCWindow.setSize(bounds.width, bounds.height);
  45.             MCWindow.setUndecorated(true);
  46.             MCWindow.setLocationRelativeTo(null);
  47.             MCWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48.             Canvas parent = new Canvas();
  49.             MCWindow.add(parent);
  50.             MCWindow.setVisible(true);
  51.             Class<?> c = loader.loadClass("org.lwjgl.opengl.Display");//get an instance of the LWJGL display class
  52.             c.getMethod("setParent", Canvas.class).invoke(null, parent);//LWJGL Display parent to our canvas
  53.         } catch (Throwable e) {
  54.             e.printStackTrace();
  55.             JOptionPane.showMessageDialog(null, e.toString());
  56.         }
  57.  
  58.         try {
  59.             //load the main class
  60.             loader.loadClass("net.minecraft.launchwrapper.Launch").getMethod("main", String[].class).invoke(null, (Object)args);
  61.         } catch (Exception e) {
  62.             e.printStackTrace();
  63.         }
  64.         loader.close();
  65.     }
  66.    
  67.     /**@returns the path to the application jar file*/
  68.     public static File getJar(){
  69.         try {
  70.             return new File(Launch.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
  71.         } catch (URISyntaxException e) {
  72.             e.printStackTrace();
  73.         }
  74.         System.err.println("Error locating jar file returning runtime directory.");
  75.         return new File("");
  76.     }
  77.    
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement