Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.launcher;
- import static fr.theshark34.swinger.Swinger.drawFullsizedImage;
- import static fr.theshark34.swinger.Swinger.getResource;
- import static fr.theshark34.swinger.Swinger.getTransparentWhite;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.IOException;
- import java.net.URL;
- import javax.swing.JCheckBox;
- import javax.swing.JEditorPane;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import javax.swing.SwingConstants;
- import javax.swing.text.html.HTMLEditorKit;
- import fr.northenflo.auth.exception.DataEmptyException;
- import fr.northenflo.auth.exception.PasswordWrongException;
- import fr.northenflo.auth.mineweb.AuthMineweb;
- import fr.northenflo.auth.mineweb.utils.TypeConnection;
- import fr.theshark34.openlauncherlib.LaunchException;
- import fr.theshark34.openlauncherlib.util.Saver;
- import fr.theshark34.openlauncherlib.util.ramselector.RamSelector;
- import fr.theshark34.swinger.Swinger;
- import fr.theshark34.swinger.colored.SColoredBar;
- import fr.theshark34.swinger.event.SwingerEvent;
- import fr.theshark34.swinger.event.SwingerEventListener;
- import fr.theshark34.swinger.textured.STexturedButton;
- @SuppressWarnings("serial")
- public class LauncherPanel extends JPanel implements SwingerEventListener {
- private Image fond = Swinger.getResource("Background.png");
- private Saver saver = new Saver(new File(Launcher.A_DIR, "launcher.properties"));
- private JTextField username = new JTextField(saver.get("username"));
- private JPasswordField password = new JPasswordField(saver.get("password"));
- private JEditorPane news = new JEditorPane();
- private STexturedButton play = new STexturedButton(getResource("Jouer.png"), getResource("Jouer.png"), getResource("Jouer.png"));
- private STexturedButton quit = new STexturedButton(getResource("Quitter.png"), getResource("Quitter.png"), getResource("Quitter.png"));
- private STexturedButton hide = new STexturedButton(getResource("Reduire.png"), getResource("Reduire.png"), getResource("Reduire.png"));
- private STexturedButton ramButton = new STexturedButton(getResource("Options.png"), getResource("Options.png"), getResource("Options.png"));
- private SColoredBar bar = new SColoredBar(getTransparentWhite(100), new Color(102, 0, 0));
- private JLabel infoLabel = new JLabel("", SwingConstants.CENTER);
- private static RamSelector selector = new RamSelector(new File(Launcher.A_DIR, "ram.txt"));
- private JCheckBox check = new JCheckBox("");
- public LauncherPanel(){
- this.setLayout(null);
- this.setBackground(Swinger.TRANSPARENT);
- news.setBounds(385, 195, 447, 389);
- news.setEditable(false);
- HTMLEditorKit kit = new HTMLEditorKit();
- news.setEditorKit(kit);
- try {
- news.setPage(new URL("http://origine-fight.fr/"));
- this.add(news);
- }
- catch (IOException e) {
- news.setContentType("text/html ");
- news.setText("Imposible de visualiser la page");
- }
- username.setForeground(Color.WHITE);
- username.setCaretColor(Color.WHITE);
- username.setFont(username.getFont().deriveFont(24F));
- username.setOpaque(false);
- username.setBorder(null);
- username.setBounds(96, 252, 222, 46);
- this.add(username);
- password.setForeground(Color.WHITE);
- password.setCaretColor(Color.WHITE);
- password.setFont(username.getFont());
- password.setOpaque(false);
- password.setBorder(null);
- password.setBounds(96, 341, 222, 46);
- this.add(password);
- play.setBounds(148, 443, 115, 47);
- play.addEventListener(this);
- this.add(play);
- hide.setBounds(752, 20, 38, 28);
- hide.addEventListener(this);
- this.add(hide);
- quit.setBounds(795, 20, 38, 28);
- quit.addEventListener(this);
- this.add(quit);
- bar.setBounds(90, 508, 246, 22);
- this.add(bar);
- infoLabel.setFont(infoLabel.getFont().deriveFont(13F));
- infoLabel.setForeground(Color.WHITE);
- infoLabel.setBounds(90, 538, 246, 24);
- this.add(infoLabel);
- ramButton.setBounds(20, 20, 39, 37);
- ramButton.addEventListener(this);
- this.add(ramButton);
- check.addActionListener(new ActionListener() {
- @SuppressWarnings("deprecation")
- @Override
- public void actionPerformed(ActionEvent e) {
- if(check.isSelected() == true) {
- saver.set("username", username.getText());
- saver.set("password", password.getText());
- }else if(check.isSelected() == false) {
- System.out.println("test");
- }
- }
- });
- check.setBounds(93, 406, 32, 32);
- this.add(check);
- selector.setFrameClass(LauncherRamSelectorWindow.class);
- }
- @SuppressWarnings({ "deprecation"})
- @Override
- public void onEvent(SwingerEvent e){
- if (e.getSource() == quit)
- System.exit(0);
- else if (e.getSource() == hide)
- LauncherFrame.getInstance().setState(JFrame.ICONIFIED);
- else if (e.getSource() == ramButton){
- selector.display();
- selector.save();
- } else if(e.getSource() == play){
- setFieldsEnabled(false);
- if(username.getText().replaceAll(" ", "").length() == 0 || password.getText().length() == 0){
- JOptionPane.showMessageDialog(this, "Erreur, pseudo ou mot de passe incorrect !", "Erreur", JOptionPane.ERROR_MESSAGE);
- setFieldsEnabled(true);
- return;
- }
- AuthMineweb.setTypeConnection(TypeConnection.launcher);
- AuthMineweb.setUrlRoot("http://origine-fight.fr/");
- AuthMineweb.setUsername(username.getText());
- AuthMineweb.setPassword(password.getText());
- try {
- AuthMineweb.start();
- } catch (PasswordWrongException e3) {
- JOptionPane.showMessageDialog(null, "Erreur, le pseudo ou le mot de passe est incorect ! ", "Erreur", JOptionPane.ERROR_MESSAGE);
- return;
- } catch (DataEmptyException e1) {
- JOptionPane.showMessageDialog(null, "hhhhh");
- return;
- } catch (IOException e2) {
- JOptionPane.showMessageDialog(null, "jjjjj");
- return;
- }
- if(AuthMineweb.isConnected())
- {
- Thread t = new Thread() {
- @Override
- public void run()
- {
- if(check.isSelected() == true) {
- saver.set("username", username.getText());
- saver.set("password", password.getText());
- }else if(check.isSelected() == false) {
- System.out.println("test");
- }
- try{
- Launcher.update();
- } catch (Exception e){
- Launcher.interruptThread();
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de mettre a jour le jeu");
- }
- try{
- Launcher.launch();
- } catch (LaunchException e){
- LauncherFrame.getCrashReporter().catchError(e, "Impossible de lancer le jeu");
- }
- }
- };t.start();
- }
- }
- }
- @Override
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- drawFullsizedImage(g, this, fond);
- }
- private void setFieldsEnabled(boolean enabled){
- username.setEnabled(enabled);
- password.setEnabled(enabled);
- play.setEnabled(enabled);
- check.setEnabled(enabled);
- }
- public SColoredBar getProgressBar(){
- return bar;
- }
- public void setInfotext(String text){
- infoLabel.setText(text);
- }
- public RamSelector getRamSelector() {
- return selector;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement