1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| package engine;
import javax.swing.JApplet;
import javax.swing.*;
import java.net.*;
import java.util.Arrays;
public class Main extends JApplet {
public void init() {
try{
java.awt.EventQueue.invokeAndWait(new Runnable(){
public void run(){
loginBox(true);
}
});
}catch(Exception e){
// Sorry, but we can't print anything anyway,
// so be a good fisher : catch it and then let it go.
} // catch's
} // init()'s
private void loginBox(boolean FirstTry){
getContentPane().removeAll();
repaint();
JLabel Consigne = new JLabel();
Consigne.setBounds(0,0,250,21);
Consigne.setText("Please enter your password :");
JLabel Echec = new JLabel();
Echec.setBounds(60,72,150,21);
Echec.setText("Wrong password.");
final JPasswordField Password = new JPasswordField();
Password.setBounds(21,21,208,30);
JButton Validation = new JButton();
Validation.setBounds(98,51,54,21);
Validation.setText("Ok");
Validation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loginRequest("username", Password.getPassword());
}
});
JLayeredPane Contenu = new JLayeredPane();
Contenu.add(Consigne, 1);
Contenu.add(Password,1);
Contenu.add(Validation, 1);
if(!FirstTry){
Contenu.add(Echec);
}
getContentPane().add(Contenu);
} // loginBox(int Tries)'s
private void loginRequest(String Username ,char[] Password){
boolean ServerAnswer = false;
char[] correctPassword = { 'n', 'u', 'n', 'a', 'v', 'u', 't' };
if(Arrays.equals(Password, correctPassword)){
ServerAnswer = true;
}
else{
ServerAnswer = false;
}
if(ServerAnswer){
initCombatScene();
}
else{
loginBox(false);
}
} // loginRequest()'s
private void initCombatScene(){
getContentPane().removeAll();
repaint();
}//initCombatScene()'s
} // Main Class' |
Partager