Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.impuuu.gghgh;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Image;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import fr.theshark34.openauth.AuthenticationException;
- import fr.theshark34.openlauncherlib.launcher.util.UsernameSaver;
- import fr.theshark34.swinger.Swinger;
- import fr.theshark34.swinger.event.SwingerEvent;
- import fr.theshark34.swinger.event.SwingerEventListener;
- import fr.theshark34.swinger.textured.STexturedButton;
- @SuppressWarnings("serial")
- public final class LauncherPanel extends JPanel implements SwingerEventListener {
- private Image background = Swinger.getResource("background.png");
- private UsernameSaver saver = new UsernameSaver(Launcher.SC_INFOS);
- private JTextField usernameField = new JTextField(saver.getUsername(""));
- private STexturedButton playbotton = new STexturedButton(Swinger.getResource("play.png"));
- private STexturedButton quitbotton = new STexturedButton(Swinger.getResource("quit.png"));
- private STexturedButton hidebotton = new STexturedButton(Swinger.getResource("hide.png"));
- public LauncherPanel() {
- this.setLayout(null);
- usernameField.setForeground(Color.GRAY);
- usernameField.setFont(usernameField.getFont().deriveFont(20F));
- usernameField.setCaretColor(Color.GRAY);
- usernameField.setOpaque(false);
- usernameField.setBorder(null);
- usernameField.setBounds(371, 323, 235, 38);
- this.add(usernameField);
- playbotton.setBounds(318, 383);
- playbotton.addEventListener(this);
- this.add(playbotton);
- quitbotton.setBounds(912, 12);
- quitbotton.addEventListener(this);
- this.add(quitbotton);
- hidebotton.setBounds(862, 12);
- hidebotton.addEventListener(this);
- this.add(hidebotton);
- }
- @Override
- public void onEvent(SwingerEvent e) {
- if(e.getSource() == playbotton){
- System.out.println("test");
- setFieldsEnabled(false);
- if(usernameField.getText().replace(" ", "").length() == 0){
- JOptionPane.showMessageDialog(this, "Erreur votre pseudo est incorect", "Erreur", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- @SuppressWarnings("unused")
- Thread th = new Thread(){
- @Override
- public void run(){
- try {
- Launcher.auth(usernameField.getText());
- } catch (AuthenticationException e) {
- JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur impossible de se connecter"+e.getErrorModel().getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- ;
- }
- System.out.println("ca marche");
- }
- };
- }else if(e.getSource() == quitbotton)
- System.exit(0);
- else if(e.getSource() == hidebotton)
- LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
- }
- t.start();
- @Override
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), this);
- }
- private void setFieldsEnabled(boolean enabled){
- usernameField.setEnabled(enabled);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement