Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.pacito2.launcher;
- import static fr.theshark34.swinger.Swinger.drawFullsizedImage;
- import static fr.theshark34.swinger.Swinger.getResource;
- import static fr.theshark34.swinger.Swinger.getTransparentWhite;
- import java.awt.Color;
- import java.awt.Desktop;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.io.File;
- import java.io.IOException;
- import java.net.URI;
- import java.net.URISyntaxException;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import javax.swing.SwingConstants;
- import fr.theshark34.openlauncherlib.util.CrashReporter;
- import fr.theshark34.openauth.AuthenticationException;
- import fr.theshark34.openlauncherlib.LaunchException;
- import fr.theshark34.openlauncherlib.util.Saver;
- import fr.theshark34.openlauncherlib.util.ramselector.RamSelector;
- import fr.theshark34.swinger.colored.SColoredBar;
- import fr.theshark34.swinger.event.SwingerEvent;
- import fr.theshark34.swinger.event.SwingerEventListener;
- import fr.theshark34.swinger.textured.STexturedButton;
- @SuppressWarnings("serial")
- public class LauncherPanel extends JPanel implements SwingerEventListener{
- private Image background = getResource("background.png");
- private Saver saver = new Saver(new File(Launcher.SC_DIR, "launcher.properties"));
- private JTextField usernameField = new JTextField(saver.get("username"));
- private STexturedButton playButton = new STexturedButton(getResource("play3.png"));
- private STexturedButton playButton2 = new STexturedButton(getResource("play3.png"));
- private STexturedButton playButton3 = new STexturedButton(getResource("play3.png"));
- private STexturedButton playButton4 = new STexturedButton(getResource("play3.png"));
- private STexturedButton Site = new STexturedButton(getResource("Site.png"));
- private STexturedButton Boutique = new STexturedButton(getResource("Boutique.png"));
- private STexturedButton Forum = new STexturedButton(getResource("Forum.png"));
- private STexturedButton Support = new STexturedButton(getResource("Support.png"));
- private STexturedButton Hide = new STexturedButton(getResource("Hide.png"));
- private STexturedButton Close = new STexturedButton(getResource("close.png"));
- private STexturedButton ramButton = new STexturedButton(getResource("ram.png"));
- private SColoredBar progressBar = new SColoredBar(getTransparentWhite(100), getTransparentWhite(175));
- private JLabel infoLabel = new JLabel("Entre ton pseudo et clique sur Play Now !", SwingConstants.CENTER);
- private RamSelector ramSelector = new RamSelector(new File(Launcher.SC_DIR, "Ram.txt"));
- public LauncherPanel(){
- this.setLayout(null);
- usernameField.setForeground(Color.BLACK);
- usernameField.setFont(usernameField.getFont().deriveFont(18F));
- usernameField.setCaretColor(Color.GRAY);
- usernameField.setOpaque(false);
- usernameField.setBorder(null);
- usernameField.setBounds(413, 71, 172, 15);
- this.add(usernameField);
- playButton.setBounds(60, 410);
- playButton.addEventListener(this);
- this.add(playButton);
- playButton2.setBounds(765, 410);
- playButton2.addEventListener(this);
- this.add(playButton2);
- playButton3.setBounds(250, 447);
- playButton3.addEventListener(this);
- this.add(playButton3);
- playButton4.setBounds(575, 447);
- playButton4.addEventListener(this);
- this.add(playButton4);
- Site.setBounds(810, 460);
- Site.addEventListener(this);
- this.add(Site);
- Boutique.setBounds(70, 463);
- Boutique.addEventListener(this);
- this.add(Boutique);
- Forum.setBounds(220, 490);
- Forum.addEventListener(this);
- this.add(Forum);
- Support.setBounds(673, 488);
- Support.addEventListener(this);
- this.add(Support);
- Hide.setBounds(930, 1);
- Hide.addEventListener(this);
- this.add(Hide);
- Close.setBounds(960, 1);
- Close.addEventListener(this);
- this.add(Close);
- ramButton.setBounds(900, 1);
- ramButton.addEventListener(this);
- this.add(ramButton);
- progressBar.setBounds(348, 110, 292, 15);
- this.add(progressBar);
- infoLabel.setForeground(Color.WHITE);
- infoLabel.setBounds(348, 110, 292, 15);
- this.add(infoLabel);
- }
- @Override
- public void onEvent(SwingerEvent e){
- if(e.getSource() == playButton){
- setFieldsEnabled(false);
- if(usernameField.getText().replaceAll(" ", "").length() == 0){
- JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- Thread t = new Thread(){
- @Override
- public void run(){
- try{
- Launcher.auth(usernameField.getText());
- } catch (AuthenticationException e){
- JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- saver.set("username", usernameField.getText());
- try{
- Launcher.update();
- } catch (Exception e){
- Launcher.interruptThread();
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure TitanCraft");
- }
- try{
- Launcher.launch();
- } catch (LaunchException e){
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer TitanCraft");
- }
- }
- };
- t.start();
- }
- else if(e.getSource() == playButton2){
- setFieldsEnabled(false);
- if(usernameField.getText().replaceAll(" ", "").length() == 0){
- JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- Thread t = new Thread(){
- @Override
- public void run(){
- try{
- Launcher2.auth(usernameField.getText());
- } catch (AuthenticationException e){
- JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- saver.set("username", usernameField.getText());
- try{
- Launcher2.update();
- } catch (Exception e){
- Launcher2.interruptThread();
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure Sindoria");
- }
- try{
- Launcher2.launch();
- } catch (LaunchException e){
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer Sindoria");
- }
- }
- };
- t.start();
- }
- else if(e.getSource() == playButton3){
- setFieldsEnabled(false);
- if(usernameField.getText().replaceAll(" ", "").length() == 0){
- JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- Thread t = new Thread(){
- @Override
- public void run(){
- try{
- Launcher3.auth(usernameField.getText());
- } catch (AuthenticationException e){
- JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- saver.set("username", usernameField.getText());
- try{
- Launcher3.update();
- } catch (Exception e){
- Launcher3.interruptThread();
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure DecayedPrison");
- }
- try{
- Launcher3.launch();
- } catch (LaunchException e){
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer DecayedPrison");
- }
- }
- };
- t.start();
- }
- else if(e.getSource() == playButton4){
- setFieldsEnabled(false);
- if(usernameField.getText().replaceAll(" ", "").length() == 0){
- JOptionPane.showMessageDialog(this, "Pseudo invalide !", "AmethystGames", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- Thread t = new Thread(){
- @Override
- public void run(){
- try{
- Launcher4.auth(usernameField.getText());
- } catch (AuthenticationException e){
- JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur : "+ e.getErrorModel().getErrorMessage(), "MineWest", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- saver.set("username", usernameField.getText());
- try{
- Launcher4.update();
- } catch (Exception e){
- Launcher4.interruptThread();
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a joure LastZ");
- }
- try{
- Launcher4.launch();
- } catch (LaunchException e){
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer LastZ");
- }
- }
- };
- t.start();
- }
- else if(e.getSource() == Close)
- System.exit(0);
- else if(e.getSource() == Hide)
- LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
- else if(e.getSource() == ramButton)
- ramSelector.display();
- else if(e.getSource() == Support)
- try {
- Desktop.getDesktop().browse(new URI("http://amethystgames.fr/Support"));
- } catch (IOException e1) {
- e1.printStackTrace();
- } catch (URISyntaxException e1) {
- e1.printStackTrace();
- }
- else if(e.getSource() == Forum)
- try {
- Desktop.getDesktop().browse(new URI("http://amethystgames.fr/Forum"));
- } catch (IOException e1) {
- e1.printStackTrace();
- } catch (URISyntaxException e1) {
- e1.printStackTrace();
- }
- else if(e.getSource() == Boutique)
- try {
- Desktop.getDesktop().browse(new URI("http://amethystgames.fr/Boutique"));
- } catch (IOException e1) {
- e1.printStackTrace();
- } catch (URISyntaxException e1) {
- e1.printStackTrace();
- }
- else if(e.getSource() == Site)
- try {
- Desktop.getDesktop().browse(new URI("http://amethystgames.fr/"));
- } catch (IOException e1) {
- e1.printStackTrace();
- } catch (URISyntaxException e1) {
- e1.printStackTrace();
- }
- }
- @Override
- public void paintComponent(Graphics graphics){
- super.paintComponent(graphics);
- drawFullsizedImage(graphics, this, background);
- }
- private void setFieldsEnabled(boolean enabled){
- usernameField.setEnabled(enabled);
- playButton.setEnabled(enabled);
- playButton2.setEnabled(enabled);
- playButton3.setEnabled(enabled);
- playButton4.setEnabled(enabled);
- Hide.setEnabled(enabled);
- Close.setEnabled(enabled);
- }
- public SColoredBar getProgressBar(){
- return progressBar;
- }
- public void setInfoText(String text){
- infoLabel.setText(text);
- }
- public RamSelector getRamSelector()
- {
- return ramSelector;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement