- 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
and name it "ServerLauncher" or w/e, and click finish. (Mines disabled cause I already created it =/)
Right click the serverlauncher package and click "New JFrame form", name it "Launcher" or w/e and click finish.
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.)
Then, switch to the source tab (You fail if you can't find it) and add a couple of imports on top
ignore it for now if its says "Unused imports".
Now, lets add the main method for opening sites.
Below this :
Add this :
The main part that executes stuff is
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:
And should take you back to the source with this or something :
Note that you can only edit the lines inbetween the method declaration.
Replace "//TODO add your handling code here:" with
(Put your site name between the quotes)
so it should look something like :
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
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 :
So it should look like this :
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?
Add this below the class declaration :
so now the top of the file should look like
Next, within the Launcher() constructor, add this -
So it should look like -
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 -
and save it to your desktop as
Now open up Netbeans again and find that runSite method we put there, replace
with
so now it should look like
And now also find the method for launching the client, and replace
with
so it should look like
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" :
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 :
You may have noticed that the program doesn't have a title. Well, follow this diagram to set it.
Now lets prepare this thing for distribution for your players
. 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.
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
and after that put
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 -
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.
-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 ._. ->
To view the content, you need to sign in or register
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1.png)
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-1.png)
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-2.png)
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-3.png)
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;
![dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-4.png)
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!");
}
}
PHP:
rt.exec("<stuff here>");
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-5.png)
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:
}
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?
To view the content, you need to sign in or register
<- 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=
PHP:
launcherprefs.properties
PHP:
String browserLocation = "<your browser location here>";
PHP:
String browserLocation = props.getProperty("browser");
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>";
PHP:
String clientLocation = props.getProperty("client");
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-6.png)
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-7.png)
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 dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-8.png)
Now lets prepare this thing for distribution for your players

![dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums dragonbIood - [Tut]How to make a multi-utility launcher for your players. - RaGEZONE Forums](http://i539.photobucket.com/albums/ff358/DragonBIood/pic1-9.png)
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)
To view the content, you need to sign in or register
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):
To view the content, you need to sign in or register
Then drag a new label above your server name and delete all text in it, and then follow this diagram :
To view the content, you need to sign in or register
Then Clean and build, and now the jar should launch with a banner on top.
Finished product :
To view the content, you need to sign in or register
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);
}
});
PHP:
JOptionPane.showMessageDialog(null, "Please remember to vote every 12 hours!");
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!");
}
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 ->
To view the content, you need to sign in or register
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: