Advertisement
Guest User

LauncherPanel

a guest
Feb 8th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1. package fr.impuuu.gghgh;
  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.JOptionPane;
  9. import javax.swing.JPanel;
  10. import javax.swing.JTextField;
  11.  
  12. import fr.theshark34.openauth.AuthenticationException;
  13. import fr.theshark34.openlauncherlib.launcher.util.UsernameSaver;
  14. import fr.theshark34.swinger.Swinger;
  15. import fr.theshark34.swinger.event.SwingerEvent;
  16. import fr.theshark34.swinger.event.SwingerEventListener;
  17. import fr.theshark34.swinger.textured.STexturedButton;
  18.  
  19. @SuppressWarnings("serial")
  20. public final class LauncherPanel extends JPanel implements SwingerEventListener {
  21.    
  22.     private Image background = Swinger.getResource("background.png");
  23.  
  24.    
  25.     private UsernameSaver saver = new UsernameSaver(Launcher.SC_INFOS);
  26.    
  27.     private JTextField usernameField = new JTextField(saver.getUsername(""));
  28.     private STexturedButton playbotton = new STexturedButton(Swinger.getResource("play.png"));
  29.     private STexturedButton quitbotton = new STexturedButton(Swinger.getResource("quit.png"));
  30.     private STexturedButton hidebotton = new STexturedButton(Swinger.getResource("hide.png"));
  31.     public LauncherPanel() {
  32.         this.setLayout(null);
  33.         usernameField.setForeground(Color.GRAY);
  34.         usernameField.setFont(usernameField.getFont().deriveFont(20F));
  35.         usernameField.setCaretColor(Color.GRAY);
  36.         usernameField.setOpaque(false);
  37.         usernameField.setBorder(null);
  38.         usernameField.setBounds(371, 323, 235, 38);
  39.         this.add(usernameField);
  40.        
  41.         playbotton.setBounds(318, 383);
  42.         playbotton.addEventListener(this);
  43.         this.add(playbotton);
  44.        
  45.         quitbotton.setBounds(912, 12);
  46.         quitbotton.addEventListener(this);
  47.         this.add(quitbotton);
  48.        
  49.         hidebotton.setBounds(862, 12);
  50.         hidebotton.addEventListener(this);
  51.         this.add(hidebotton);
  52.     }
  53.  
  54.     @Override
  55.     public void onEvent(SwingerEvent e) {
  56.         if(e.getSource() == playbotton){
  57.             System.out.println("test");
  58.             setFieldsEnabled(false);
  59.            
  60.             if(usernameField.getText().replace(" ", "").length() == 0){
  61.             JOptionPane.showMessageDialog(this, "Erreur votre pseudo est incorect", "Erreur", JOptionPane.ERROR_MESSAGE);
  62.             setFieldsEnabled(true);
  63.             return;
  64.         }
  65.            
  66.         @SuppressWarnings("unused")
  67.         Thread th = new Thread(){
  68.             @Override
  69.             public void run(){
  70.                     try {
  71.                         Launcher.auth(usernameField.getText());
  72.                     } catch (AuthenticationException e) {
  73.                         JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur impossible de se connecter"+e.getErrorModel().getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
  74.                         setFieldsEnabled(true);
  75.                         return;
  76. ;
  77.                     }
  78.                     System.out.println("ca marche");
  79.  
  80.             }  
  81.  
  82.         };
  83.     }else if(e.getSource() == quitbotton)
  84.             System.exit(0);
  85.          else if(e.getSource() == hidebotton)
  86.              LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
  87.         }
  88.        
  89.     t.start();
  90.    
  91.     @Override
  92.     public void paintComponent(Graphics g){
  93.         super.paintComponent(g);
  94.        
  95.        
  96.         g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), this);
  97.     }
  98.     private void setFieldsEnabled(boolean enabled){
  99.         usernameField.setEnabled(enabled);
  100.        
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement