Advertisement
Guest User

Untitled

a guest
Aug 9th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. package com.fxlauncher.fr;
  2.  
  3. import fr.theshark34.openauth.AuthenticationException;
  4.  
  5. import javax.swing.*;
  6. import java.awt.*;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.io.IOException;
  10.  
  11. public class LauncherFrame extends JFrame implements ActionListener {
  12.  
  13. private static LauncherFrame instance;
  14.  
  15. private JLabel titre, beta, user, pass, dl;
  16. private JTextField pseudo;
  17. private JPasswordField mdp;
  18. private JButton jouer;
  19. private JProgressBar pb;
  20.  
  21. private String username = null;
  22. private String accessToken = null;
  23. private String id = null;
  24.  
  25. public LauncherFrame() {
  26. this.setTitle("Fenyx-MC Launcher");
  27. this.setSize(850, 500);
  28. this.setUndecorated(true);
  29. this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  30. this.setLocationRelativeTo(null);
  31. this.setLayout(null);
  32. this.getContentPane().setBackground(new Color(100, 64, 150));
  33.  
  34. titre = new JLabel("Fenyx-MC", SwingConstants.CENTER);
  35. titre.setForeground(Color.WHITE);
  36. titre.setFont(titre.getFont().deriveFont(60f));
  37. titre.setBounds(0, 20, 850, 100);
  38. this.add(titre);
  39.  
  40. beta = new JLabel("Ceci est une BETA ! Pour le moment rien n'est modifié sur MC", SwingConstants.CENTER);
  41. beta.setForeground(Color.WHITE);
  42. beta.setFont(titre.getFont().deriveFont(20f));
  43. beta.setBounds(0, 70, 850, 100);
  44. this.add(beta);
  45.  
  46. user = new JLabel("Email");
  47. user.setForeground(Color.WHITE);
  48. user.setFont(titre.getFont().deriveFont(10f));
  49. user.setBounds(300, 275, 150, 20);
  50. this.add(user);
  51.  
  52. pass = new JLabel("Pass");
  53. pass.setForeground(Color.WHITE);
  54. pass.setFont(titre.getFont().deriveFont(10f));
  55. pass.setBounds(300, 305, 150, 20);
  56. this.add(pass);
  57.  
  58. pseudo = new JTextField("");
  59. pseudo.setBounds(350, 275, 150, 20);
  60. this.add(pseudo);
  61.  
  62. mdp = new JPasswordField("");
  63. mdp.setBounds(350, 305, 150, 20);
  64. this.add(mdp);
  65.  
  66. jouer = new JButton("Lancer le jeu");
  67. // Enregistre la fenetre entant qu'ActionListener
  68. jouer.addActionListener(this);
  69. jouer.setBounds(350, 335, 150, 20);
  70. this.add(jouer);
  71.  
  72. dl = new JLabel("", SwingConstants.CENTER);
  73. dl.setForeground(Color.WHITE);
  74. dl.setFont(titre.getFont().deriveFont(15f));
  75. dl.setBounds(0, 460, 850, 20);
  76. this.add(dl);
  77.  
  78. pb = new JProgressBar();
  79. pb.setStringPainted(true);
  80. pb.setBounds(0, 480, 850, 20);
  81. this.add(pb);
  82.  
  83. this.setVisible(true);
  84. }
  85.  
  86. @Override
  87. public void actionPerformed(ActionEvent e) {
  88. Thread t = new Thread() {
  89. @Override
  90. public void run() {
  91. pseudo.setEnabled(false);
  92. mdp.setEnabled(false);
  93. jouer.setEnabled(false);
  94. try {
  95. Launcher.update();
  96. } catch (IOException e1) {
  97. // Affichage d'un message d'erreur
  98. JOptionPane.showMessageDialog(null, "Impossible de mettre a jour le launcher ! : " + e, "Erreur !", JOptionPane.ERROR_MESSAGE);
  99. // On reactive tout
  100. pseudo.setEnabled(true);
  101. mdp.setEnabled(true);
  102. jouer.setEnabled(true);
  103. // On affiche l'erreur
  104. e1.printStackTrace();
  105. }
  106. try {
  107. Launcher.auth(pseudo.getText(), new String(mdp.getPassword()));
  108. Launcher.launch();
  109. } catch (AuthenticationException e) {
  110. // Si ça n'a pas marché on réactive tout
  111. pseudo.setEnabled(true);
  112. mdp.setEnabled(true);
  113. jouer.setEnabled(true);
  114. // On affiche l'erreur
  115. e.printStackTrace();
  116. // Et on affiche un message d'erreur
  117. JOptionPane.showMessageDialog(LauncherFrame.this, "Impossible de se connecter : " + e.getErrorModel().getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
  118. }
  119. }
  120. };
  121. t.start();
  122. }
  123.  
  124. public static void main(String[] args) {
  125. // Astuce pour avoir le style visuel du systeme hôte
  126. try {
  127. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  128. } catch (Exception e) {
  129. e.printStackTrace();
  130. }
  131. instance = new LauncherFrame();
  132. }
  133.  
  134. // Retourne l'instance de LauncherFrame
  135. public static LauncherFrame getInstance() {
  136. return instance;
  137. }
  138.  
  139. // Retourne l'instance de notre progress bar
  140. public JProgressBar getProgressBar() {
  141. return pb;
  142. }
  143. public JLabel getDl() {
  144. return dl;
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement