Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fxlauncher.fr;
- import fr.theshark34.openauth.AuthenticationException;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.IOException;
- public class LauncherFrame extends JFrame implements ActionListener {
- private static LauncherFrame instance;
- private JLabel titre, beta, user, pass, dl;
- private JTextField pseudo;
- private JPasswordField mdp;
- private JButton jouer;
- private JProgressBar pb;
- private String username = null;
- private String accessToken = null;
- private String id = null;
- public LauncherFrame() {
- this.setTitle("Fenyx-MC Launcher");
- this.setSize(850, 500);
- this.setUndecorated(true);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- this.setLayout(null);
- this.getContentPane().setBackground(new Color(100, 64, 150));
- titre = new JLabel("Fenyx-MC", SwingConstants.CENTER);
- titre.setForeground(Color.WHITE);
- titre.setFont(titre.getFont().deriveFont(60f));
- titre.setBounds(0, 20, 850, 100);
- this.add(titre);
- beta = new JLabel("Ceci est une BETA ! Pour le moment rien n'est modifié sur MC", SwingConstants.CENTER);
- beta.setForeground(Color.WHITE);
- beta.setFont(titre.getFont().deriveFont(20f));
- beta.setBounds(0, 70, 850, 100);
- this.add(beta);
- user = new JLabel("Email");
- user.setForeground(Color.WHITE);
- user.setFont(titre.getFont().deriveFont(10f));
- user.setBounds(300, 275, 150, 20);
- this.add(user);
- pass = new JLabel("Pass");
- pass.setForeground(Color.WHITE);
- pass.setFont(titre.getFont().deriveFont(10f));
- pass.setBounds(300, 305, 150, 20);
- this.add(pass);
- pseudo = new JTextField("");
- pseudo.setBounds(350, 275, 150, 20);
- this.add(pseudo);
- mdp = new JPasswordField("");
- mdp.setBounds(350, 305, 150, 20);
- this.add(mdp);
- jouer = new JButton("Lancer le jeu");
- // Enregistre la fenetre entant qu'ActionListener
- jouer.addActionListener(this);
- jouer.setBounds(350, 335, 150, 20);
- this.add(jouer);
- dl = new JLabel("", SwingConstants.CENTER);
- dl.setForeground(Color.WHITE);
- dl.setFont(titre.getFont().deriveFont(15f));
- dl.setBounds(0, 460, 850, 20);
- this.add(dl);
- pb = new JProgressBar();
- pb.setStringPainted(true);
- pb.setBounds(0, 480, 850, 20);
- this.add(pb);
- this.setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- Thread t = new Thread() {
- @Override
- public void run() {
- pseudo.setEnabled(false);
- mdp.setEnabled(false);
- jouer.setEnabled(false);
- try {
- Launcher.update();
- } catch (IOException e1) {
- // Affichage d'un message d'erreur
- JOptionPane.showMessageDialog(null, "Impossible de mettre a jour le launcher ! : " + e, "Erreur !", JOptionPane.ERROR_MESSAGE);
- // On reactive tout
- pseudo.setEnabled(true);
- mdp.setEnabled(true);
- jouer.setEnabled(true);
- // On affiche l'erreur
- e1.printStackTrace();
- }
- try {
- Launcher.auth(pseudo.getText(), new String(mdp.getPassword()));
- Launcher.launch();
- } catch (AuthenticationException e) {
- // Si ça n'a pas marché on réactive tout
- pseudo.setEnabled(true);
- mdp.setEnabled(true);
- jouer.setEnabled(true);
- // On affiche l'erreur
- e.printStackTrace();
- // Et on affiche un message d'erreur
- JOptionPane.showMessageDialog(LauncherFrame.this, "Impossible de se connecter : " + e.getErrorModel().getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
- }
- }
- };
- t.start();
- }
- public static void main(String[] args) {
- // Astuce pour avoir le style visuel du systeme hôte
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (Exception e) {
- e.printStackTrace();
- }
- instance = new LauncherFrame();
- }
- // Retourne l'instance de LauncherFrame
- public static LauncherFrame getInstance() {
- return instance;
- }
- // Retourne l'instance de notre progress bar
- public JProgressBar getProgressBar() {
- return pb;
- }
- public JLabel getDl() {
- return dl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement