Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tut]How to make a multi-utility launcher for your players.

Junior Spellweaver
Joined
Jul 11, 2008
Messages
118
Reaction score
16
This guide/tutorial will teach you how to make a custom launcher for your server in Java, the main features will be-
-Ability to launch the client (through the program).
-Ability to launch your forums/main website(through the program)
-Ability to launch your voting site(through the program)
-Save the file locations for the browser/client in a property file (more on this later).

Mainly made this cause I was bored lol, and thought this might teach people some more 'bout java :S
--------------------------------------------------------------------------------------------

Lets get started!

First off, the only program you need to follow this guide is Netbeans, if you don't have it go google it and download it.

Table of Contents -
I. The Main Application/Required Code
II. Extra Addons
III. FAQ and Credits



I. Writing The Main Application
For a project like this, we will need a GUI for the convenience of players, so we'll be using Swing.
What is Swing? Well, read this ._. ->

So to make a GUI in Java, Netbeans makes it easy. Open it up and create a new java application
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


and name it "ServerLauncher" or w/e, and click finish. (Mines disabled cause I already created it =/)
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


Right click the serverlauncher package and click "New JFrame form", name it "Launcher" or w/e and click finish.

dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


Now lay out your basic interface (under the "design" tab) like mine, 1 label and 4 buttons and rename them by right click -> edit text (Pretty intuitive, its drag and drop) (Yes its not very pretty, I'll show you how to add some stuff to make it look nice later lol) (Replace Your Server Name Here with your server name if you haven't done so.)
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


Then, switch to the source tab (You fail if you can't find it) and add a couple of imports on top
PHP:
import javax.swing.*;
import java.io.*;
import java.util.Properties;
ignore it for now if its says "Unused imports".
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


Now, lets add the main method for opening sites.
Below this :

PHP:
    /** Creates new form Launcher */
    public Launcher() {
        initComponents();
    }

Add this :
PHP:
//This method will open up sites in the specified browser
public static void runSite(String sitename) {
        try {
           String browserLocation = "C:\\Users\\Alex Zhang\\Desktop\\Firefox\\firefox.exe";
            Runtime rt = Runtime.getRuntime();
            rt.exec(browserLocation + " " + sitename);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error! Could not find browser!");
        }
    }
The main part that executes stuff is
PHP:
rt.exec("<stuff here>");
basically "stuff here" is a command prompt command, equivalent of "start " and then the stuff in quotes.

Replace "C:\\Users\\Alex Zhang\\Desktop\\Firefox\\firefox.exe" with the location of your browser, yes I know that some people's browser directories may differ from yours, we'll add that later. BTW the '\' in directory paths must be replaced by "\\" or else you'll get an error. Now let's add some basic functionality to the buttons! Return to the design tab, right click the "Launch Site" button, and follow this picture:
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums

And should take you back to the source with this or something :

PHP:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }
Note that you can only edit the lines inbetween the method declaration.

Replace "//TODO add your handling code here:" with
PHP:
runSite("<yoursitenamehere>");

(Put your site name between the quotes)
so it should look something like :
PHP:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
      runSite("google.com");
    }

google.com is just an example. Now try testing it out! Press shift+f6 to run it and press the "Launch Website" button and see if it opens up your browser and launches your website which it should, if it doesn't and says "Error, could not find browser!" then your browser path is not right, I'm using the same code and it launches google normally on my firefox.

Now, do the same with the other browser related buttons, like "Vote!" and "Launch Forums"(Right click the button ->Events ->Action -> actionPerformed), just in the method bodies put the corresponding sites instead of your main website. So you should now have 3 methods like this

PHP:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
      runSite("google.com"); //Your site link
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
      runSite("forum.ragezone.com"); //Your forum link
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        runSite("xtremetop100.com"); //your voting site link
    }

Now what about the method to launch the client? Make the method the same way as the others, and paste this code in the body :
PHP:
        try {
            Runtime rt = Runtime.getRuntime();
            String clientLocation = ""; //Put the path to your client here
            Process pr = rt.exec(clientLocation);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error! Could not find client!");
        }

So it should look like this :
PHP:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            Runtime rt = Runtime.getRuntime();
            String clientLocation = ""; //Put the path to your client here
            Process pr = rt.exec(clientLocation);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error! Could not find client!");
        }
    }

Put the path to your client inside the quotes for String clientLocation = "". Again, we'll deal with people having different path locations later.

So now your program should be able to launch your website, forums, voting site, and client now, test by pressing shift+f6 and pressing the different buttons.

Congrats! Your program is halfway done, but not ready to be distributed to your players yet. We still have to modify the jar to run the Launcher as the main class and let the user be able to set the directory of where their client/website.

How can we accomplish that? By using property files. What is a property file?
<- There ya go.

Add this below the class declaration :
PHP:
 private static Properties props = new Properties();

so now the top of the file should look like
PHP:
public class Launcher extends javax.swing.JFrame {
    private static Properties props = new Properties();
    /** Creates new form Launcher */
    public Launcher() {
        initComponents();
    }

Next, within the Launcher() constructor, add this -
PHP:
        try {
            props.load(new FileInputStream(System.getProperty("user.dir") + "\\launcherprefs.properties"));
        } catch (Exception e) {
            e.printStackTrace();
        }

So it should look like -
PHP:
    public Launcher() {
        try {
            props.load(new FileInputStream(System.getProperty("user.dir") + "\\launcherprefs.properties"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        initComponents();
    }

What this ensures is that the properties file MUST be in the same directory as the jar (The file people will be running to launch the Launcher) is in.

Lets create the properties file now! Open up notepad and put this in -
PHP:
#Preferences for the Launcher
#Put the path to your client here
client=
#Put the path to your browser here (e.g firefox)
browser=
and save it to your desktop as
PHP:
launcherprefs.properties
Now open up Netbeans again and find that runSite method we put there, replace
PHP:
 String browserLocation = "<your browser location here>";
with
PHP:
String browserLocation = props.getProperty("browser");
so now it should look like
PHP:
    public static void runSite(String sitename) {
        try {
            String browserLocation = props.getProperty("browser");
            Runtime rt = Runtime.getRuntime();
            rt.exec(browserLocation + " " + sitename);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error! Could not find browser!");
        }
    }

And now also find the method for launching the client, and replace
PHP:
 String clientLocation = "<your client location here>";
with
PHP:
String clientLocation = props.getProperty("client");
so it should look like
PHP:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            Runtime rt = Runtime.getRuntime();
            String clientLocation = props.getProperty("client");
            Process pr = rt.exec(clientLocation);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error! Could not find client!");
        }
    }

Alright! Now find the directory this project is in, and drag the "launcherprefs.properties" we made earlier in it.
(For me its "C:\Users\Alex Zhang\Desktop\Alex Folder\ServerLauncher", don't put it in the sub folders like dist, src, etc.).
Open it up (with notepad obviously) and put your client and browser paths where the comments ask for them after the = signs, like client=<directorypathhere>(Make sure to have NO spaces after the directories for the files or else it might not launch properly and error) (In property files # is the equivalent of //) (Property files also need a \\ instead of a \ for file paths.)

save, and now try running the launcher with shift+f6 again and you should be able to open the sites/client like normal.

Now, time to clean it up and add the finishing touches.

First of all, Netbeans should've generated a class called "Main.java", we honestly don't need that so delete it.
For those of you who are "visual learners" :

dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


Now we gotta set the main class to run in the jar "Launcher.java" to do so or else it won't run properly. Do so by right clicking the project and click "properties", its the last option and then follow this picture :
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


You may have noticed that the program doesn't have a title. Well, follow this diagram to set it.
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums


Now lets prepare this thing for distribution for your players :p. Right click the project and click clean and build. Go to your project folder and you should see a jar in the dist folder. Make a new folder on your desktop entitled <your server name here>'s Launcher. Drag the jar from the dist folder into that folder and also make a clean properties file (see above) and drag it in.
dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums




Then rar it. (Your need winrar, google and download it if you don't have it lol) If you don't know how, right click -> Add to archive. Then you can upload it to mediafire and voil?*! Your server now has a half-baked launcher that your players can download :S.

Make sure you tell your players for it to work to put the appropriate file locations in the .properties file AND they don't have extra spaces in the directory name.


This is what is should look like when launched (Whoops reached max amount of photos)


II. Extra Addons

A. How to add a banner

Go back to the Design tab and resize the frame slightly larger and move all buttons/labels down. How much to resize depends on how big your banner is. Now copy (ctrl + c) and paste (ctrl + v) your banner's image into the package the Launcher.java is in.
Here's a visual of what I just said (I'm using a banner I made in 5 secs lol):


Then drag a new label above your server name and delete all text in it, and then follow this diagram :


Then Clean and build, and now the jar should launch with a banner on top.

Finished product :


B. Vote popup upon startup.
Basically what this will do is show a popup saying "Please vote" when a player executes the launcher. Find
PHP:
 public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Launcher().setVisible(true);
            }
        });
and after that put
PHP:
JOptionPane.showMessageDialog(null, "Please remember to vote every 12 hours!");
Note that for you it may not be new Launcher().setVisible(true); , it depends on what you named your class. So now the main method should be -
PHP:
 public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Launcher().setVisible(true);
            }
        });
        JOptionPane.showMessageDialog(null, "Please remember to vote every 12 hours!");
    }
Working on it right now~ (Vote reminder, File selection GUI, Info page, Windows look and feel, and how to put your banner in the program is what I'm gonna add.)

III.
FAQ and Credits.


Q: Dammmmmmmnnnnnn this launcher looks like a piece of ****

A: Customize it yourself, my point was to make a basic one that worked.

Q: ZOMG IT DOESN'T LAUNCH ANYTHING AND JUST SAYS "CAN'T FIND BROWSER"

A: Make sure your file paths are correct in your properties, use \\ not \ for property files, and make sure theres no extra white spaces. Also, make sure your property file is in the same file location as the jar, like if the jar is on the desktop the property file must be on the desktop too. If its in a folder, the property file must be in that folder too. Also make sure that its named launcherprefs.properties.

Q: I get a compiling error !!111

A: Post it on this thread o.o

Q: Whats this "file path" you keep talking about?
A: The location of a file on your hard drive.

Q: Why does the GUI look weird?
A: Its called the "Metal" look and feel and is the default for Java GUIs, I'll post in add-ons how to make it look like a Windows GUI

Q: Where can I find out how to make more programs like this?
A: the Java website has an extensive tutorial on it, here's the link ->


This Guide was made by me, and I don't care if you post it on other forums as long as these credits stay on it.

Thanks for reading my guide, if you spot any errors please post it below, this is my first guide anyways.
 
Last edited:
Newbie Spellweaver
Joined
Jan 4, 2009
Messages
19
Reaction score
1
Haha beautiful guide, we need more of these people who know how to actually present instead of people like Moogra who just say they did stuff.
 
Newbie Spellweaver
Joined
Apr 29, 2008
Messages
59
Reaction score
0
Apparently, I still can't get it to run.
I quadruple checked the file paths, There were no spaces and they went directly to the program. The launching worked before I used the properties file, Also the Serverlauncher.jar and the properties are in the same folder.
 
Junior Spellweaver
Joined
Jul 30, 2009
Messages
142
Reaction score
2
Cant wait till you add how to put the banner in
Btw awesome release
Noob friendly (me friendly lol)

Edit : Lol wtf? I double click it and it doesnt start

heres the code :

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* GUI.java
*
* Created on 12-Aug-2009, 1:31:27 PM
*/

package xmusicmsstarter;

/**
*
* @author Admin
*/
import javax.swing.*;
import java.io.*;
import java.util.Properties;
public class GUI extends javax.swing.JFrame {
private static Properties props = new Properties();
/** Creates new form GUI */
public GUI() {
try {
props.load(new FileInputStream(System.getProperty("user.dir") + "\\launcherprefs.properties"));
} catch (Exception e) {
e.printStackTrace();
}
initComponents();
}

//This method will open up sites in the specified browser
public static void runSite(String sitename) {
try {
String browserLocation = props.getProperty("browser");
Runtime rt = Runtime.getRuntime();
rt.exec(browserLocation + " " + sitename);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error! You fail, your Firefox is not in its default directory!");
}
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("xMusicMs");
setBackground(new java.awt.Color(153, 0, 153));

jButton1.setText("Play");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel1.setFont(new java.awt.Font("DilleniaUPC", 0, 72)); // NOI18N
jLabel1.setForeground(new java.awt.Color(153, 0, 153));
jLabel1.setText("xMusicMs");

jButton2.setText("Website");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("Vote");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.setText("Forums");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(**** **** 112)
.addComponent(jLabel1)
.addContainerGap(120, Short.MAX_VALUE))
.addComponent(jButton4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
);

pack();
}// </editor-fold>

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
runSite("http://www.xMusicMs.tk");
}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
runSite("http://www.xMusicMs.forummotion.com");
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
runSite("http://topsites.ragezone.com/index.php?do=votes&id=71");
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Runtime rt = Runtime.getRuntime();
String clientLocation = props.getProperty("client"); //Put the path to your client here
Process pr = rt.exec(clientLocation);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error! You Suck and have not extracted everything to C:\\Nexon\\Maplestory!");
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}

And the properties

#Preferences for the Launcher
#Put the path to your client here
client=C:\Nexon\MapleStory\dontclick.exe
#Comes with a default of Nexon\MapleStory
#Put the path to your browser here (e.g firefox)
browser=C:\Program Files (x86)\Mozilla Firefox\firefox.exe
#Comes with a default of firefox
 
Last edited:
Junior Spellweaver
Joined
Jul 11, 2008
Messages
118
Reaction score
16
Hm... so when you click the .jar it doesn't start at all? Make sure you set the main class. PMed you.
 
Last edited:
Xephizion Development
Loyal Member
Joined
Apr 19, 2008
Messages
906
Reaction score
31
Good Job ;)
 
Junior Spellweaver
Joined
Jul 11, 2008
Messages
118
Reaction score
16
EDIT Sorry everyone I just realized that in the property files you DO need a \\ instead of a \ for file paths. Edited the guide too.
 
Last edited:
Legendary Battlemage
Loyal Member
Joined
Jul 13, 2009
Messages
671
Reaction score
139
Haha beautiful guide, we need more of these people who know how to actually present instead of people like Moogra who just say they did stuff.

It the persons choice whether too spoon feed Ducking idiots, or not.
 
Mythic Archon
Loyal Member
Joined
May 11, 2008
Messages
722
Reaction score
50
This is dumb tbh.
How many of your players are gonna have JDK?
 
Junior Spellweaver
Joined
Jul 11, 2008
Messages
118
Reaction score
16
This is dumb tbh.
How many of your players are gonna have JDK?

... The point of the guide was to have the server owner make the .jar file and distributes it to his/her players. They only need the JRE to run it.
 
Junior Spellweaver
Joined
Jul 30, 2009
Messages
142
Reaction score
2
Most ppl have JRE
btw I thanked 3 times xP

It would be kewl If making an .exe starter would be this easy
 
Xephizion Development
Loyal Member
Joined
Apr 19, 2008
Messages
906
Reaction score
31
i use Visual Basic to make those stuffs
 
bleh....
Loyal Member
Joined
Oct 15, 2008
Messages
2,898
Reaction score
1,129
Haha beautiful guide, we need more of these people who know how to actually present instead of people like Moogra who just say they did stuff.

are you serious or joking? Moogra has done alot for the private server community, including releasing repacks that many noobs still use.
 
Xephizion Development
Loyal Member
Joined
Apr 19, 2008
Messages
906
Reaction score
31
Moogra was my hero till he/she started trollin :p:
 
Junior Spellweaver
Joined
Jul 11, 2008
Messages
118
Reaction score
16
I actually suggest using C# winforms instead of java.

I have done a (tiny) bit of C# and found making a winform pretty similar to Java , I just wasn't used to the API @_@ (And the convention... I'm not used to the first word in method names being capitalized like Console.WriteLine)
 
Back
Top