Skip to content

Commit

Permalink
add a option to run minecraft, close #13
Browse files Browse the repository at this point in the history
  • Loading branch information
robin4002 committed Jan 8, 2016
1 parent 0c48035 commit f8d833a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ public void run()
@Override
public void onFinish()
{
JOptionPane.showMessageDialog(null, LANG.getTranslation("installation.success"), LANG.getTranslation("misc.success"), JOptionPane.INFORMATION_MESSAGE);
SuccessFrame credit = new SuccessFrame();
credit.setVisible(true);
}

@Override
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/fr/minecraftforgefrance/installer/SuccessFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package fr.minecraftforgefrance.installer;

import static fr.minecraftforgefrance.common.Localization.LANG;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class SuccessFrame extends JFrame
{
private static final long serialVersionUID = 1L;

public SuccessFrame()
{
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setTitle(LANG.getTranslation("misc.success"));
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setResizable(false);
this.setSize(300, 100);
this.setLayout(new BorderLayout());
JPanel panel = new JPanel();
JLabel label = new JLabel(LANG.getTranslation("installation.success"));
label.setAlignmentX(CENTER_ALIGNMENT);
label.setAlignmentY(TOP_ALIGNMENT);
panel.add(label);
this.getContentPane().add(panel, BorderLayout.CENTER);

JPanel buttonPanel = new JPanel();
JButton exit = new JButton(LANG.getTranslation("scr.btn.exit"));
exit.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
SuccessFrame.this.dispose();
}
});
buttonPanel.add(exit);
JButton runGame = new JButton(LANG.getTranslation("scr.btn.run"));
runGame.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
try
{
@SuppressWarnings("resource")
Class<?> launcherMainClass = new URLClassLoader(new URL[] {(new File(Installer.frame.mcDir, "launcher.jar")).toURI().toURL()}).loadClass("net.minecraft.launcher.Main");
java.lang.reflect.Method m = launcherMainClass.getMethod("main", String[].class);
String[] params = new String[]{"workDir", Installer.frame.mcDir.toString()};
m.invoke(null, (Object)params);
}
catch(Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, LANG.getTranslation("err.runminecraft"), LANG.getTranslation("misc.error"), JOptionPane.ERROR_MESSAGE);
}
SuccessFrame.this.dispose();
}
});
buttonPanel.add(runGame);
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);

int x = (dim.width / 2) - (this.getSize().width / 2);
int y = (dim.height / 2) - (this.getSize().height / 2);
this.setLocation(x, y);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/langs/EN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ err.bigimage=The image is too big!
err.cannotfindlocalinfo=Local information not found, file /installer/local_info.json is missing in the jar
err.invalidjson=The local json is not valid, please check it with this website : http://jsonlint.com/
err.erroredprofile=Errored profile, please re-install it!
err.runminecraft=can't run the game, run it manually

# Tasks done
file.unpacked.success=Successfully unpacked %s
Expand Down Expand Up @@ -75,6 +76,8 @@ scr.btn.install=Install
scr.btn.credits=Credits
scr.btn.webSite=Web site
scr.btn.options=Options
scr.btn.exit=Exit
scr.btn.run=Run Minecraft

# CREDITS
scr.credits.html=Installer created by %s with the help of %s (GUI) and %s (translation system)<br>Thank to %s, creator of the Forge installer that served as an inspiration
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/langs/FR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ err.bigimage=L'image est trop grande
err.cannotfindlocalinfo=Informations locales introuvables, le fichier /installer/local_info.json est manquant dans le .jar
err.invalidjson=Json local invalide, veuillez le vérifiez avec http://jsonlint.com/
err.erroredprofile=Profil érroné, veuiller utiliser le launcher officiel pour corriger cela!
err.runminecraft=Impossible de lancer Minecraft, lancez-le manuellement

# Tâches effectuées
file.unpacked.success=%s à été décompressé
Expand Down Expand Up @@ -74,6 +75,8 @@ scr.btn.install=Installer
scr.btn.credits=Crédits
scr.btn.webSite=Site web
scr.btn.options=Options
scr.btn.exit=Fermer
scr.btn.run=Lancer Minecraft

# CRÉDITS
scr.credits.html=Installateur créé par %s avec la contribution de %s (interface) et %s (système de traduction)<br>Remerciement à %s, créateur de l'installateur de Forge qui a servi de source d'inspiration
Expand Down

0 comments on commit f8d833a

Please sign in to comment.