
Yes, this has been released before. I am basing this off a previous release.
This can be used for ANY client, but in the example I am using the clients Matrix uses.---
Hello! Today we are going to be adding a splash screen to our client. It's a pretty simple process.
What we are doing exactly... BTC (Behind the Code)So, what we are going to do is make a new java file, SplashScreen.java, load when our client starts. In this SplashScreen class, we will have some variables that control the look of out splash screen when it appears and then our little
showSplash() method, which shows our splash screen (Duh!).
Adding the codeMake a new java file and name it "SplashScreen". Add the following into it:
import java.awt.*;
import javax.swing.*;
import java.net.URL;
import javax.imageio.ImageIO;
/**
* SplashScreen - Shows splash screen and starts client.
*
* @author Arham 4
* @author Klepto
*/
public class SplashScreen extends JWindow {
/**
* Splash screen duration (milliseconds).
*/
private static int splashDuration = 5000;
/**
* Splash screen image.
*/
private static String fileUrl = "http://i.imgur.com/kOLYMBd.png";
/**
* The dimensions of the splash screen.
*/
private static int[] dimensions = {619, 349};
/**
* Shows splash screen in the center of desktop.
*/
public static void showSplash() {
Image image = null;
try {
URL url = new URL(fileUrl);
image = ImageIO.read(url);
} catch (Exception e) {
e.printStackTrace();
}
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
frame.setSize(dimensions[0], dimensions[1]);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
JLabel label = new JLabel(new ImageIcon(image));
frame.add(label);
frame.setVisible(true);
try { Thread.sleep(splashDuration); } catch (Exception e) {}
frame.setVisible(false);
}
}
splashDuration: int - This variables controls how long our splash screen stays on the screen (in milliseconds). You can choose to be cruel and make it 60000 (1 minute) or you can be nice and make it 2500 (2.5 seconds). Your choice.fileUrl: String - Here's something that didn't come in the Splash screen released a while back. And... this is also the reason why I made a new tutorial. This system is based on URL, whereas the previous was based on file, which would be bad because in our 667+ clients, we use Update Server, not auto-cache download, so we can't really transfer our file to another person's computer. Thus, let's just use an online URL?dimensions: int[] - These are the dimensions of the image. You want to make it exact.showSplash(): void - This is what initializes our splash screen.Now, you want to go to Loader.java and find:
public static void main(String[] args) {
This method is the first method run by Java to run our client.
Add the following directly below it:
SplashScreen splash = new SplashScreen();
splash.showSplash();
This makes the splash screen load as soon as the client starts.
A more deeper look into the code.I need to make this qualify as a tutorial, so lets look at the
showSplash() method.
/**
* Shows splash screen in the center of desktop.
*/
public static void showSplash() {
Image image = null;
try {
URL url = new URL(fileUrl);
image = ImageIO.read(url);
} catch (Exception e) {
e.printStackTrace();
}
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
frame.setSize(dimensions[0], dimensions[1]);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
JLabel label = new JLabel(new ImageIcon(image));
frame.add(label);
frame.setVisible(true);
try { Thread.sleep(splashDuration); } catch (Exception e) {}
frame.setVisible(false);
}
So first, we load the image from the URL we specified.
Image image = null;
try {
URL url = new URL(fileUrl);
image = ImageIO.read(url);
} catch (Exception e) {
e.printStackTrace();
}
Then, we make our JFrame.
JFrame frame = new JFrame();
And then we remove the window pane.
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
Next, we set the dimensions.
frame.setSize(dimensions[0], dimensions[1]);
After that, we make the splash screen appear at the center of the screen.
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
After doing that, we load our image onto the JFrame.
JLabel label = new JLabel(new ImageIcon(image));
frame.add(label);
Then we set our JFrame as visible.
frame.setVisible(true);
Next, we make the thread of the client "sleep", so it makes the pause that we said in the splashDuration.
try { Thread.sleep(splashDuration); } catch (Exception e) {}
After the little nap our Thread had, we make the frame not visible, so the client can load.
frame.setVisible(false);
---
And we are done.
Tip: Don't use puush for uploading the image, the ImageIO for some reason throws an exception for puush.
Thanks for reading,
Arham
P.S: My first time I EVER worked with the client. Clients really scare the hell out of me.