Guest User

Untitled

a guest
Mar 10th, 2019
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.titanium.launcher;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JLabel;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.JPanel;
  11. import javax.swing.JPasswordField;
  12. import javax.swing.JTextField;
  13. import javax.swing.SwingConstants;
  14.  
  15. import fr.theshark34.openauth.AuthenticationException;
  16. import fr.theshark34.openlauncherlib.launcher.util.UsernameSaver;
  17. import fr.theshark34.swinger.Swinger;
  18. import fr.theshark34.swinger.colored.SColoredBar;
  19. import fr.theshark34.swinger.event.SwingerEvent;
  20. import fr.theshark34.swinger.event.SwingerEventListener;
  21. import fr.theshark34.swinger.textured.STexturedButton;
  22.  
  23. @SuppressWarnings("serial")
  24. public class LauncherPanel extends JPanel implements SwingerEventListener {
  25.  
  26. private Image background = Swinger.getResource("LauncherFrame.png") ;
  27.  
  28. private UsernameSaver saver = new UsernameSaver(Launcher.TT_INFOS) ;
  29.  
  30. private JTextField usernameField = new JTextField(saver.getUsername("")) ;
  31. private JTextField passwordField = new JPasswordField() ;
  32.  
  33. private STexturedButton playButton = new STexturedButton(Swinger.getResource("LauncherBouton.png")) ;
  34. private STexturedButton hideButton = new STexturedButton(Swinger.getResource("LauncherReduireBouton.png")) ;
  35. private STexturedButton quitButton = new STexturedButton(Swinger.getResource("LauncherCloseBouton.png")) ;
  36.  
  37. private SColoredBar progressBar = new SColoredBar(new Color(255, 255, 255, 15) ) ;
  38. private JLabel infoLabel = new JLabel("Clique Sur Jouer !", SwingConstants.CENTER) ;
  39.  
  40.  
  41. public LauncherPanel() {
  42. this.setLayout(null);
  43.  
  44. usernameField.setOpaque(false);
  45. usernameField.setFont(usernameField.getFont().deriveFont(25F));
  46. usernameField.setBorder(null);
  47. usernameField.setForeground(Color.WHITE);
  48. usernameField.setCaretColor(Color.WHITE);
  49. usernameField.setBounds(193, 235, 307, 38);
  50. this.add(usernameField) ;
  51.  
  52. passwordField.setOpaque(false);
  53. passwordField.setFont(passwordField.getFont().deriveFont(25F));
  54. passwordField.setBorder(null);
  55. passwordField.setForeground(Color.WHITE);
  56. passwordField.setCaretColor(Color.WHITE);
  57. passwordField.setBounds(193, 351, 307, 38);
  58. this.add(passwordField) ;
  59.  
  60. playButton.setBounds(190, 435);
  61. playButton.addEventListener(this);
  62. this.add(playButton) ;
  63.  
  64. quitButton.setBounds(935, 0);
  65. quitButton.addEventListener(this);
  66. this.add(quitButton) ;
  67.  
  68. hideButton.setBounds(890, 0);
  69. hideButton.addEventListener(this);
  70. this.add(hideButton) ;
  71.  
  72.  
  73.  
  74.  
  75. progressBar.setBounds(12, 593, 961, 20);
  76. this.add(progressBar) ;
  77.  
  78. infoLabel.setBounds(12, 560, 951, 25);
  79. infoLabel.setForeground(Color.WHITE);
  80. infoLabel.setFont(usernameField.getFont());
  81. this.add(infoLabel) ;
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. @SuppressWarnings("unused")
  90. @Override
  91. public void onEvent(SwingerEvent e) {
  92. if(e.getSource() == playButton) {
  93. setFieldEnabled(false) ;
  94.  
  95. if(usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 0) {
  96.  
  97. JOptionPane.showMessageDialog(this, "Erreur, Veuillez Entrer Une Adresse Mail Et Un Pseudo Valides.", "Erreur", JOptionPane.ERROR_MESSAGE);
  98. setFieldEnabled(true) ;
  99.  
  100. return ;
  101. }
  102.  
  103.  
  104. Thread t = new Thread() {
  105.  
  106. @Override
  107. public void run() {
  108. try {
  109. Launcher.auth(usernameField.getText(), passwordField.getText());
  110. } catch (AuthenticationException e) {
  111.  
  112. if(usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 0) {
  113.  
  114. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, Imposible De Se Connecter : " + e.getErrorModel().getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
  115. setFieldEnabled(true) ;
  116.  
  117. return ;
  118.  
  119. }
  120.  
  121. try {
  122. Launcher.update();
  123. } catch (Exception e1) {
  124.  
  125. Launcher.interruptThread() ;
  126. JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, Imposible De Mettre Le Jeu A Jour : " + e1, "Erreur", JOptionPane.ERROR_MESSAGE);
  127. setFieldEnabled(true) ;
  128.  
  129. return ;
  130.  
  131. }
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. }
  139.  
  140.  
  141.  
  142.  
  143. } ;
  144.  
  145. };
  146. }
  147.  
  148. else if(e.getSource() == quitButton)
  149. System.exit(0) ;
  150. else if(e.getSource() == hideButton)
  151. LauncherFrame.getInstance().setState(JFrame.ICONIFIED) ;
  152. }
  153.  
  154.  
  155. @Override
  156. public void paintComponent(Graphics g) {
  157. super.paintComponent(g);
  158.  
  159. g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), this);
  160.  
  161.  
  162. }
  163.  
  164.  
  165. private void setFieldEnabled(boolean enabled) {
  166.  
  167. usernameField.setEnabled(enabled);
  168.  
  169. passwordField.setEnabled(enabled);
  170.  
  171. playButton.setEnabled(enabled);
  172.  
  173.  
  174. }
  175.  
  176. public SColoredBar getProgressBar() {
  177.  
  178. return progressBar ;
  179.  
  180. }
  181.  
  182. public void setInfoText(String text) {
  183. infoLabel.setText(text);
  184. }
  185.  
  186.  
  187.  
  188. }
RAW Paste Data