Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1. package fr.launcher;
  2.  
  3. import static fr.theshark34.swinger.Swinger.drawFullsizedImage;
  4. import static fr.theshark34.swinger.Swinger.getResource;
  5. import static fr.theshark34.swinger.Swinger.getTransparentWhite;
  6.  
  7. import java.awt.Color;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import java.net.URL;
  15.  
  16. import javax.swing.JCheckBox;
  17. import javax.swing.JEditorPane;
  18. import javax.swing.JFrame;
  19. import javax.swing.JLabel;
  20. import javax.swing.JOptionPane;
  21. import javax.swing.JPanel;
  22. import javax.swing.JPasswordField;
  23. import javax.swing.JTextField;
  24. import javax.swing.SwingConstants;
  25. import javax.swing.text.html.HTMLEditorKit;
  26.  
  27. import fr.northenflo.auth.exception.DataEmptyException;
  28. import fr.northenflo.auth.exception.PasswordWrongException;
  29. import fr.northenflo.auth.mineweb.AuthMineweb;
  30. import fr.northenflo.auth.mineweb.utils.TypeConnection;
  31. import fr.theshark34.openlauncherlib.LaunchException;
  32. import fr.theshark34.openlauncherlib.util.Saver;
  33. import fr.theshark34.openlauncherlib.util.ramselector.RamSelector;
  34. import fr.theshark34.swinger.Swinger;
  35. import fr.theshark34.swinger.colored.SColoredBar;
  36. import fr.theshark34.swinger.event.SwingerEvent;
  37. import fr.theshark34.swinger.event.SwingerEventListener;
  38. import fr.theshark34.swinger.textured.STexturedButton;
  39.  
  40. @SuppressWarnings("serial")
  41. public class LauncherPanel extends JPanel implements SwingerEventListener {
  42.  
  43. private Image fond = Swinger.getResource("Background.png");
  44.  
  45. private Saver saver = new Saver(new File(Launcher.A_DIR, "launcher.properties"));
  46.  
  47. private JTextField username = new JTextField(saver.get("username"));
  48. private JPasswordField password = new JPasswordField(saver.get("password"));
  49. private JEditorPane news = new JEditorPane();
  50.  
  51. private STexturedButton play = new STexturedButton(getResource("Jouer.png"), getResource("Jouer.png"), getResource("Jouer.png"));
  52. private STexturedButton quit = new STexturedButton(getResource("Quitter.png"), getResource("Quitter.png"), getResource("Quitter.png"));
  53. private STexturedButton hide = new STexturedButton(getResource("Reduire.png"), getResource("Reduire.png"), getResource("Reduire.png"));
  54. private STexturedButton ramButton = new STexturedButton(getResource("Options.png"), getResource("Options.png"), getResource("Options.png"));
  55.  
  56. private SColoredBar bar = new SColoredBar(getTransparentWhite(100), new Color(102, 0, 0));
  57. private JLabel infoLabel = new JLabel("", SwingConstants.CENTER);
  58. private static RamSelector selector = new RamSelector(new File(Launcher.A_DIR, "ram.txt"));
  59. private JCheckBox check = new JCheckBox("");
  60.  
  61. public LauncherPanel(){
  62.  
  63. this.setLayout(null);
  64. this.setBackground(Swinger.TRANSPARENT);
  65.  
  66. news.setBounds(385, 195, 447, 389);
  67. news.setEditable(false);
  68. HTMLEditorKit kit = new HTMLEditorKit();
  69.  
  70. news.setEditorKit(kit);
  71.  
  72. try {
  73. news.setPage(new URL("http://origine-fight.fr/"));
  74. this.add(news);
  75. }
  76. catch (IOException e) {
  77. news.setContentType("text/html ");
  78. news.setText("Imposible de visualiser la page");
  79. }
  80.  
  81. username.setForeground(Color.WHITE);
  82. username.setCaretColor(Color.WHITE);
  83. username.setFont(username.getFont().deriveFont(24F));
  84. username.setOpaque(false);
  85. username.setBorder(null);
  86. username.setBounds(96, 252, 222, 46);
  87. this.add(username);
  88.  
  89. password.setForeground(Color.WHITE);
  90. password.setCaretColor(Color.WHITE);
  91. password.setFont(username.getFont());
  92. password.setOpaque(false);
  93. password.setBorder(null);
  94. password.setBounds(96, 341, 222, 46);
  95. this.add(password);
  96.  
  97. play.setBounds(148, 443, 115, 47);
  98. play.addEventListener(this);
  99. this.add(play);
  100.  
  101. hide.setBounds(752, 20, 38, 28);
  102. hide.addEventListener(this);
  103. this.add(hide);
  104.  
  105. quit.setBounds(795, 20, 38, 28);
  106. quit.addEventListener(this);
  107. this.add(quit);
  108.  
  109. bar.setBounds(90, 508, 246, 22);
  110. this.add(bar);
  111.  
  112. infoLabel.setFont(infoLabel.getFont().deriveFont(13F));
  113. infoLabel.setForeground(Color.WHITE);
  114. infoLabel.setBounds(90, 538, 246, 24);
  115. this.add(infoLabel);
  116.  
  117. ramButton.setBounds(20, 20, 39, 37);
  118. ramButton.addEventListener(this);
  119. this.add(ramButton);
  120.  
  121. check.addActionListener(new ActionListener() {
  122.  
  123. @SuppressWarnings("deprecation")
  124. @Override
  125. public void actionPerformed(ActionEvent e) {
  126.  
  127. if(check.isSelected() == true) {
  128.  
  129. saver.set("username", username.getText());
  130. saver.set("password", password.getText());
  131.  
  132. }else if(check.isSelected() == false) {
  133.  
  134. System.out.println("test");
  135.  
  136. }
  137.  
  138. }
  139. });
  140. check.setBounds(93, 406, 32, 32);
  141. this.add(check);
  142.  
  143. selector.setFrameClass(LauncherRamSelectorWindow.class);
  144.  
  145. }
  146.  
  147. @SuppressWarnings({ "deprecation"})
  148. @Override
  149. public void onEvent(SwingerEvent e){
  150.  
  151. if (e.getSource() == quit)
  152. System.exit(0);
  153. else if (e.getSource() == hide)
  154. LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
  155. else if (e.getSource() == ramButton){
  156. selector.display();
  157. selector.save();
  158. } else if(e.getSource() == play){
  159. setFieldsEnabled(false);
  160.  
  161. if(username.getText().replaceAll(" ", "").length() == 0 || password.getText().length() == 0){
  162. JOptionPane.showMessageDialog(this, "Erreur, pseudo ou mot de passe incorrect !", "Erreur", JOptionPane.ERROR_MESSAGE);
  163. setFieldsEnabled(true);
  164. return;
  165. }
  166.  
  167. AuthMineweb.setTypeConnection(TypeConnection.launcher);
  168. AuthMineweb.setUrlRoot("http://origine-fight.fr/");
  169. AuthMineweb.setUsername(username.getText());
  170. AuthMineweb.setPassword(password.getText());
  171. try {
  172. AuthMineweb.start();
  173. } catch (PasswordWrongException e3) {
  174. JOptionPane.showMessageDialog(null, "Erreur, le pseudo ou le mot de passe est incorect ! ", "Erreur", JOptionPane.ERROR_MESSAGE);
  175. return;
  176. } catch (DataEmptyException e1) {
  177. JOptionPane.showMessageDialog(null, "hhhhh");
  178. return;
  179. } catch (IOException e2) {
  180. JOptionPane.showMessageDialog(null, "jjjjj");
  181. return;
  182. }
  183. if(AuthMineweb.isConnected())
  184. {
  185. Thread t = new Thread() {
  186. @Override
  187. public void run()
  188. {
  189. if(check.isSelected() == true) {
  190.  
  191. saver.set("username", username.getText());
  192. saver.set("password", password.getText());
  193.  
  194. }else if(check.isSelected() == false) {
  195.  
  196. System.out.println("test");
  197.  
  198. }
  199.  
  200. try{
  201. Launcher.update();
  202.  
  203. } catch (Exception e){
  204. Launcher.interruptThread();
  205. LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a jour le jeu");
  206. }
  207.  
  208. try{
  209. Launcher.launch();
  210.  
  211. } catch (LaunchException e){
  212. LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer le jeu");
  213.  
  214. }
  215. }
  216. };t.start();
  217.  
  218.  
  219. }
  220. }
  221. }
  222.  
  223. @Override
  224. public void paintComponent(Graphics g){
  225.  
  226. super.paintComponent(g);
  227.  
  228. drawFullsizedImage(g, this, fond);
  229.  
  230. }
  231.  
  232.  
  233. private void setFieldsEnabled(boolean enabled){
  234. username.setEnabled(enabled);
  235. password.setEnabled(enabled);
  236. play.setEnabled(enabled);
  237. check.setEnabled(enabled);
  238. }
  239.  
  240. public SColoredBar getProgressBar(){
  241. return bar;
  242. }
  243.  
  244. public void setInfotext(String text){
  245. infoLabel.setText(text);
  246. }
  247.  
  248. public RamSelector getRamSelector() {
  249. return selector;
  250.  
  251. }
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement