ClearRelic24

Untitled

Jun 11th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. package me.clearrelic24.crservlauncher;
  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.  
  14. import fr.theshark34.openauth.AuthenticationException;
  15. import fr.theshark34.openlauncherlib.launcher.util.UsernameSaver;
  16. import fr.theshark34.swinger.Swinger;
  17. import fr.theshark34.swinger.colored.SColoredBar;
  18. import fr.theshark34.swinger.event.SwingerEvent;
  19. import fr.theshark34.swinger.event.SwingerEventListener;
  20. import fr.theshark34.swinger.textured.STexturedButton;
  21.  
  22. @SuppressWarnings("serial")
  23. public class LauncherPanel extends JPanel implements SwingerEventListener{
  24.  
  25.  
  26.  
  27. private Image font = Swinger.getResource("background.jpg");
  28.  
  29. private UsernameSaver Saver = new UsernameSaver(Launcher.CRSERV_INFOS);
  30. private JTextField usernameField = new JTextField(Saver.getUsername(""));
  31.  
  32. private JPasswordField passwordField = new JPasswordField();
  33.  
  34. private STexturedButton PlayButtom = new STexturedButton(Swinger.getResource("play.jpg"));
  35. private STexturedButton QuitButtom = new STexturedButton(Swinger.getResource("Quit.jpg"));
  36. private STexturedButton HideButtom = new STexturedButton(Swinger.getResource("Reduire.jpg"));
  37.  
  38. private SColoredBar progressbar = new SColoredBar(Swinger.getTransparentWhite(95), Swinger.getTransparentInstance(Color.YELLOW, 100));
  39. private JLabel infoLabel = new JLabel("CRServ Launcher by ClearRelic24");
  40.  
  41.  
  42. public LauncherPanel() {
  43. this.setLayout(null);
  44. usernameField.setForeground(Color.YELLOW);
  45. usernameField.setFont(usernameField.getFont().deriveFont(20f));
  46. usernameField.setCaretColor(Color.YELLOW);
  47. usernameField.setOpaque(false);
  48. usernameField.setBorder(null);
  49. usernameField.setBounds(640, 380, 275, 40);
  50. this.add(usernameField);
  51.  
  52. passwordField.setForeground(Color.YELLOW);
  53. passwordField.setFont(usernameField.getFont().deriveFont(20f));
  54. passwordField.setCaretColor(Color.YELLOW);
  55. passwordField.setOpaque(false);
  56. passwordField.setBorder(null);
  57. passwordField.setBounds(640, 525, 275, 40);
  58. this.add(passwordField);
  59.  
  60. HideButtom.setBounds(33, 5);
  61. HideButtom.addEventListener(this);
  62. this.add(HideButtom);
  63.  
  64. QuitButtom.setBounds(3, 5);
  65. QuitButtom.addEventListener(this);
  66. this.add(QuitButtom);
  67.  
  68. PlayButtom.setBounds(530, 450);
  69. PlayButtom.addEventListener(this);
  70. this.add(PlayButtom);
  71.  
  72. progressbar.setBounds(25, 605, 900, 5);
  73. this.add(progressbar);
  74.  
  75. infoLabel.setForeground(Color.ORANGE);
  76. infoLabel.setBounds(25, 595, 900, 10);
  77. this.add(infoLabel);
  78. }
  79.  
  80. @SuppressWarnings("deprecation")
  81. @Override
  82. public void onEvent(SwingerEvent e) {
  83. if(e.getSource() == PlayButtom) {
  84. setFieldEnabled(false);
  85.  
  86. if(usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 0) {
  87. JOptionPane.showMessageDialog(this, "Échec d'authentification. Nom d'utilisateur ou mot de passe invalide", "Échec d'authentification", JOptionPane.ERROR_MESSAGE);
  88. setFieldEnabled(true);
  89. return;
  90. }
  91. Thread t = new Thread() {
  92. @Override
  93. public void run() {
  94.  
  95. try {
  96.  
  97.  
  98. Launcher.auth(usernameField.getText(), passwordField.getText());
  99. } catch (AuthenticationException e) {
  100. JOptionPane.showMessageDialog(LauncherPanel.this, "Connection impossible:"+ e.getErrorModel().getErrorMessage(), "Échec d'authentification", JOptionPane.ERROR_MESSAGE);
  101. setFieldEnabled(true);
  102.  
  103. }try {
  104.  
  105.  
  106. Launcher.update();
  107. } catch (Exception e) {
  108. JOptionPane.showMessageDialog(LauncherPanel.this, "Mise à jour impossible:"+ e, "Mise à jour", JOptionPane.ERROR_MESSAGE);
  109. setFieldEnabled(true);
  110.  
  111. }try {
  112.  
  113.  
  114. Launcher.launch();
  115. } catch (Exception e) {
  116. JOptionPane.showMessageDialog(LauncherPanel.this, "Lancement impossible:"+ e, "Erreur de lancement", JOptionPane.ERROR_MESSAGE);
  117. setFieldEnabled(true);
  118.  
  119. }
  120.  
  121.  
  122. System.out.println("Authentification réussi");
  123. }
  124. };
  125. t.start();
  126.  
  127. }else if (e.getSource() == QuitButtom){
  128. System.exit(0);
  129. }else if(e.getSource() == HideButtom) {
  130. LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
  131. }
  132.  
  133.  
  134.  
  135. }
  136. @Override
  137. public void paintComponent(Graphics g) {
  138. super.paintComponent(g);
  139.  
  140.  
  141. g.drawImage(font, 0, 0, this.getWidth(), this.getHeight(), this);
  142. }
  143. private void setFieldEnabled(boolean enabled) {
  144. usernameField.setEnabled(enabled);
  145. passwordField.setEnabled(enabled);
  146. PlayButtom.setEnabled(enabled);
  147. }
  148. public SColoredBar getProgressBar() {
  149. return progressbar;
  150.  
  151. }
  152. public void setInfoText(String text) {
  153. infoLabel.setText(text);
  154. }
  155.  
  156. }
Add Comment
Please, Sign In to add comment